home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 37 / Amiga Format CD37 (1999-02-16)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-03].iso / -screenplay- / shareware / invasionforce / source / map_editor.c < prev    next >
C/C++ Source or Header  |  1999-01-09  |  118KB  |  3,169 lines

  1. /*
  2.    map_editor.c -- map editor module for Invasion Force
  3.    This module provides the Invasion Force map editor.
  4.    This source code is free.  You may make as many copies as you like.
  5. */
  6.  
  7. // standard header for all program modules
  8. #include "global.h"
  9. #include "gadgets_protos.h"
  10.  
  11. struct Menu *editor_menu_strip = NULL;
  12.  
  13. // globals for the map editor
  14. BOOL MEdit = FALSE;
  15. BOOL INFO = FALSE;
  16. BOOL terminated = FALSE;
  17. BOOL mapgen = FALSE;
  18. BOOL mycity = FALSE;
  19. int brush = HEX_PLAINS;
  20. int tot = 0;
  21. int totP = 0;
  22. int figctr[] = {
  23.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  24. };
  25. int infoctr[] = {
  26.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  27. };
  28.  
  29.  
  30. /*
  31.    This section is devoted to loading and saving the map files.
  32. */
  33.  
  34. int map_safe;      // Is it safe to leave without saving my map?
  35.  
  36. char map_filepath[108] = "ProgDir:Maps/", map_filename[108] = "Earth.MAP";
  37.  
  38.  
  39. void save_map(filename)
  40. char *filename;
  41.  
  42. {
  43.    struct rtHandlerInfo *handle;
  44.    BPTR file;
  45.  
  46.    sprintf(foo,"Saving map file:\n   `%s'",filename);
  47.    handle = post_it(foo);
  48.    SetPointer(map_window,BUSY_POINTER);
  49.  
  50.    file = Open(filename,MODE_NEWFILE);
  51.    if (file == NULL) {
  52.       DisplayBeep(map_screen);
  53.       alert(map_window,NULL,"Unable to open file!\nMap not saved.","Drat!");
  54.       unpost_it(handle);
  55.       ClearPointer(map_window);
  56.       return;
  57.    FI
  58.  
  59.    Write(file,"EMP2MAP\0",8L);  // magic identifies my saved maps
  60.    Write(file,&revision,2L);     // current revision of Invasion Force
  61.    Write(file,&wrap,sizeof(wrap));
  62.    Write(file,&width,sizeof(width));
  63.    Write(file,&height,sizeof(height));
  64.    Write(file,t_grid,GRID_SIZE*2);
  65.  
  66.    {  // save the cities!
  67.       struct City *metro = (struct City *)city_list.mlh_Head;
  68.       int num_cities = count_nodes(&city_list);
  69.  
  70.       Write(file,&num_cities,sizeof(num_cities));
  71.       for ( ; metro->cnode.mln_Succ; metro = (struct City *)metro->cnode.mln_Succ)
  72.          Write(file,&metro->col,(long)(sizeof(*metro)-sizeof(metro->cnode)));
  73.    }
  74.    Close(file);
  75.  
  76.    // Set the filenote.
  77.    SetComment(filename,"Invasion Force -- saved map");
  78.  
  79.    ClearPointer(map_window);
  80.    alert(map_window,NULL,"Map saved!","Okay");
  81.    unpost_it(handle);
  82. }
  83.  
  84.  
  85. BOOL load_map(filename)
  86. char *filename;
  87. {
  88.    BPTR file;
  89.    BOOL new_wrap;
  90.    int new_width, new_height;
  91.    short revcheck;
  92.  
  93.    file = Open(filename,MODE_OLDFILE);
  94.    if (file == NULL) {
  95.       DisplayBeep(map_screen);
  96.       alert(map_window,NULL,"Unable to open file!\nMap not loaded.","Drat!");
  97.       return FALSE;
  98.    FI
  99.  
  100.    Read(file,foo,8L);
  101.    if (strncmp(foo,"EMP2MAP",8)) {
  102.       Close(file);
  103.       sprintf(foo,"[%s] is not a valid map file!",filename);
  104.       alert(map_window,NULL,foo,"Oops!");
  105.       return FALSE;
  106.    FI
  107.    Read(file,&revcheck,2L);
  108.    if (revcheck<6 || revcheck>revision) {
  109.       Close(file);
  110.       sprintf(foo,"That is not an Invasion Force 0.06--0.%d map file!", revision);
  111.       alert(map_window,NULL,foo,"Oops!");
  112.       return FALSE;
  113.    }
  114.  
  115.    if (revcheck<revision) {
  116.       (void)rtEZRequestTags(\
  117.          "WARNING!\nThat map is from an older revision of Invasion Force.\nYou should re-save it for future compatibility.",
  118.          "Duly Noted",NULL,NULL,
  119.          RT_Window,        map_window,
  120.          RT_ReqPos,        REQPOS_CENTERSCR,
  121.          RT_LockWindow,    TRUE,
  122.          RTEZ_Flags,       EZREQF_CENTERTEXT,
  123.          TAG_DONE );
  124.    FI
  125.  
  126.    Read(file,&new_wrap,(long)sizeof(new_wrap));
  127.    Read(file,&new_width,(long)sizeof(new_width));
  128.    Read(file,&new_height,(long)sizeof(new_height));
  129.    // sanity check
  130.    if (new_width<MIN_WD || new_height<MIN_HT) {
  131.       Close(file);
  132.       alert(map_window,NULL,"That is not a valid map file!","Oops!");
  133.       return FALSE;
  134.    FI
  135.    wrap = new_wrap;  width = new_width;   height = new_height;
  136.    nuke_list(&city_list);  // wipe out all the old cities
  137.    if (alloc_map(&t_grid)==FALSE) {
  138.       Close(file);
  139.       alert(map_window,NULL,"There's not enough RAM for that map!","Drat!");
  140.       width = disp_wd; height = disp_ht;
  141.       if (alloc_map(&t_grid)==FALSE)
  142.          clean_exit(2,"ERROR: Fatal RAM allocation disaster!");
  143.       ClearPointer(map_window);
  144.       flood_map(t_grid,HEX_OCEAN);
  145.       return FALSE;
  146.    FI
  147.    if (revcheck<13)
  148.       Read(file,t_grid,GRID_SIZE);
  149.    else
  150.       Read(file,t_grid,GRID_SIZE*2);
  151.  
  152.    // convert the old ARCTIC terrain to plains
  153.    if (revcheck<13) {
  154.       int cx, cy, terra;
  155.       for (cx=0; cx<width; cx++)
  156.          for (cy=0; cy<height; cy++) {
  157.             terra = get(t_grid,cx,cy);
  158.             if (terra==HEX_ARCTIC) {
  159.                terra = HEX_PLAINS;
  160.                put(t_grid,cx,cy,terra);
  161.             FI
  162.          OD
  163.    FI
  164.  
  165.    {  // load the cities, if there are any
  166.       int num_cities;
  167.  
  168.       Read(file,&num_cities,(long)sizeof(num_cities));
  169.       if (num_cities>0) {
  170.          int ctr;
  171.          struct City *flarp;
  172.  
  173.          for (ctr=1; ctr<=num_cities; ctr++) {
  174.             flarp = AllocVec((int)sizeof(*flarp),MEMF_CLEAR);
  175.             if (revcheck<9) {
  176.                struct OldCity *foozle;
  177.                int ctr2;
  178.  
  179.                Read(file,&flarp->col,(long)(sizeof(*foozle)-sizeof(flarp->cnode)));
  180.                for (ctr2=0;ctr2<9;ctr2++)
  181.                   flarp->recon[ctr2] = CITY;
  182.             } else
  183.                Read(file,&flarp->col,(long)(sizeof(*flarp)-sizeof(flarp->cnode)));
  184.             if (revcheck<10)
  185.                flarp->specialty = CITY;
  186.             AddTail((struct List *)&city_list,(struct Node *)flarp);
  187.          OD
  188.       FI
  189.    }
  190.    Close(file);
  191.    return TRUE;
  192. }
  193.  
  194.  
  195. // This handles loading a map file for the editor.
  196.  
  197. void ME_load_map(filename)
  198. char *filename;
  199. {
  200.    struct rtHandlerInfo *handle;
  201.  
  202.    sprintf(foo,"Loading map file:\n   `%s'",filename);
  203.    handle = post_it(foo);
  204.    SetPointer(map_window,BUSY_POINTER);
  205.  
  206.    if (load_map(filename))
  207.       alert(map_window,NULL,"Map loaded!","Okay");
  208.  
  209.    ClearPointer(map_window);
  210.    unpost_it(handle);
  211.  
  212.    // update the display for the new map
  213.    xoffs = yoffs = 0;
  214.    update_scrollers();
  215.    ME_draw_map();
  216. }
  217.  
  218. #define LOAD 0
  219. #define SAVE -1
  220.  
  221. void rt_loadsave_map(save)
  222. int save;
  223. {  // load or save using the ReqTools file requester
  224.    struct rtFileRequester *req = NULL;
  225.    char pan[216];  // pan = Path And Name
  226.    BOOL chosen;
  227.  
  228.    req = rtAllocRequestA(RT_FILEREQ,NULL);
  229.    if (req==NULL) {
  230.       alert(map_window,NULL,"Failed to allocate ReqTools file requester.","Drat!");
  231.       return;
  232.    FI
  233.  
  234.    rtChangeReqAttr(req,
  235.       RTFI_Dir,map_filepath,
  236.       RTFI_MatchPat,"#?.MAP",
  237.       TAG_END);
  238.    
  239.    
  240.    chosen = (BOOL)rtFileRequest(req,map_filename,(save ? "Save Map" : "Load Map"),
  241.       RTFI_Flags, (save ? FREQF_SAVE : NULL) | FREQF_PATGAD,
  242.       RT_DEFAULT, TAG_END);
  243.    if (chosen) {
  244.       int dirlen = strlen(req->Dir);
  245.       strcpy(map_filepath,req->Dir);
  246.       strcpy(pan,map_filepath);
  247.       if (dirlen)
  248.          if (map_filepath[dirlen-1]!='/' && map_filepath[dirlen-1]!=':')
  249.             strcat(pan,"/");
  250.       strcat(pan,map_filename);
  251.    } else {
  252.       rtFreeRequest(req);
  253.       return;
  254.    FI
  255.    rtFreeRequest(req);
  256.  
  257.    if (save)
  258.       save_map(pan);
  259.    else
  260.       ME_load_map(pan);
  261.    map_safe = TRUE;
  262. }
  263.  
  264. /*
  265.    This section is devoted to the map size window, where the user
  266.    sets the map width, height and the wrap-around option.
  267. */
  268.  
  269. void try_map_resize(new_width,new_height)
  270. int new_width,new_height;
  271. {  // attempt to resize the map to these dimensions
  272.    int old_width = width, old_height = height;
  273.  
  274.    if (new_width==old_width && new_height==old_height)
  275.       return;
  276.  
  277.    if (new_width<MIN_WD || new_height<MIN_HT) {
  278.       sprintf(foo,"The minimum size for maps is %ld wide, %ld high.",MIN_WD,MIN_HT);
  279.       alert(map_window,NULL,foo,"Oops!");
  280.       return;
  281.    FI
  282.  
  283.    if (new_height%2) {
  284.       alert(map_window,NULL,"The map height must be an even value!","Oops!");
  285.       return;
  286.    FI
  287.  
  288.    map_safe = TRUE;
  289.    width = new_width;      height = new_height;
  290.    if (alloc_map(&t_grid)==FALSE) {
  291.       alert(map_window,NULL,"I can't create a map of that size!\n    Perhaps you need more RAM?","Drat!");
  292.       width = old_width;   height = old_height;
  293.       if (alloc_map(&t_grid)==FALSE)
  294.          clean_exit(2,"ERROR: Fatal RAM allocation disaster!");
  295.    FI
  296.  
  297.    xoffs = yoffs = 0; // reset the scrolly gadgets
  298.    update_scrollers();
  299.    flood_map(t_grid,HEX_OCEAN);     // default starting conditions
  300. }
  301.  
  302.  
  303. void map_size_request()
  304. {
  305.    BOOL resize_flag = FALSE;
  306.    struct Window *mapsize_window = NULL;
  307.  
  308.    struct Gadget *context, *width_gad, *height_gad, *wrap_gad, *okay_gad, *cancel_gad;
  309.    struct NewGadget button = {
  310.       98,64,      // leftedge, topedge
  311.       66,16,   // width, height
  312.       "Okay",  // text label
  313.       NULL,    // font
  314.       4,       // gadget ID
  315.       NULL,NULL,NULL
  316.    }, intfield = {
  317.       90,41,      // leftedge, topedge
  318.       72,16,   // width, height
  319.       "_Height:", // text label
  320.       NULL,    // font
  321.       5,       // gadget ID
  322.       PLACETEXT_LEFT,
  323.       NULL,NULL
  324.    }, toggle = {
  325.       178,32,     // leftedge, topedge
  326.       24,24,   // width, height
  327.       "W_rap-Around Map",  // text label
  328.       NULL,    // font
  329.       6,       // gadget ID
  330.       PLACETEXT_RIGHT,
  331.       NULL,NULL
  332.    };
  333.  
  334.    // make sure user doesn't play with the map window now
  335.    SetPointer(map_window,BUSY_POINTER);
  336.    ModifyIDCMP(map_window,NULL);
  337.  
  338.    // create the [Okay] and [Cancel] buttons
  339.    if (!CreateContext(&context))
  340.       clean_exit(1,"Unable to create context gadget!");
  341.    button.ng_VisualInfo = vi;
  342.    button.ng_TextAttr = &topaz11bold;
  343.    okay_gad = CreateGadget(BUTTON_KIND,context,&button,TAG_END);
  344.    button.ng_LeftEdge = 193;
  345.    button.ng_GadgetText = "Cancel";
  346.    button.ng_TextAttr = &topaz11;
  347.    button.ng_Flags = NULL;
  348.    cancel_gad = CreateGadget(BUTTON_KIND,okay_gad,&button,TAG_END);
  349.  
  350.    // create the Height and Width fields
  351.    intfield.ng_VisualInfo = vi;
  352.    intfield.ng_TextAttr = &topaz11;
  353.    height_gad = CreateGadget(INTEGER_KIND,cancel_gad,&intfield,
  354.       GTIN_Number, height,
  355.       GT_Underscore, '_',
  356.       GTIN_MaxChars, 6, TAG_END);
  357.    intfield.ng_GadgetText = "_Width:";
  358.    intfield.ng_TopEdge = 20;
  359.    width_gad = CreateGadget(INTEGER_KIND,height_gad,&intfield,
  360.       GTIN_Number, width,
  361.       GT_Underscore, '_',
  362.       GTIN_MaxChars, 6, TAG_END);
  363.  
  364.    // create the Wrap gadget
  365.    toggle.ng_VisualInfo = vi;
  366.    toggle.ng_TextAttr = &topaz11;
  367.    wrap_gad = CreateGadget(CHECKBOX_KIND,width_gad,&toggle,
  368.       GTCB_Checked, wrap,
  369.       GT_Underscore, '_',
  370.       TAG_END);
  371.  
  372.    // do the window itself
  373.    mapsize_window = OpenWindowTags(NULL,
  374.       WA_Gadgets,context,
  375.       WA_Title,"Map Size",
  376.       WA_CustomScreen,map_screen,
  377.       WA_Top,155,    WA_Left,141,
  378.       WA_Height,88,  WA_Width,357,
  379.       WA_IDCMP,IDCMP_GADGETUP|IDCMP_VANILLAKEY,
  380.       WA_Flags,NOCAREREFRESH|WFLG_DRAGBAR|WFLG_ACTIVATE,
  381.       TAG_END );
  382.    if (mapsize_window==NULL)
  383.       clean_exit(1,"ERROR: Unable to open map size window!");
  384.  
  385.    {  // handle the user actions here
  386.       struct IntuiMessage *message; // the message the IDCMP sends us
  387.  
  388.       // useful for interpreting IDCMP messages
  389.       UWORD code;
  390.       ULONG class;
  391.       APTR object;
  392.       UWORD qualifier;
  393.  
  394.       FOREVER {
  395.          WaitPort(mapsize_window->UserPort);
  396.          while (message = GT_GetIMsg(mapsize_window->UserPort)) {
  397.             code = message->Code;  // MENUNUM
  398.             object = message->IAddress;  // Gadget
  399.             class = message->Class;
  400.             qualifier = message->Qualifier;
  401.             GT_ReplyIMsg(message);
  402.             if (class==IDCMP_VANILLAKEY) {
  403.                switch ((char)code) {
  404.                   case 'w':
  405.                      ActivateGadget(width_gad,mapsize_window,NULL);
  406.                      break;
  407.                   case 'h':
  408.                      ActivateGadget(height_gad,mapsize_window,NULL);
  409.                      break;
  410.                   case 'r':
  411.                      // toggle the wrap gadget
  412.                      setselect(wrap_gad,!selected(wrap_gad));
  413.                      RefreshGList(wrap_gad,mapsize_window,NULL,1);
  414.                      break;
  415.                   case 'v':   // default for OKAY
  416.                      if ((qualifier & IEQUALIFIER_LCOMMAND)==0)
  417.                         break;
  418.                   case 13:    // default for OKAY
  419.                      // show the button depressed
  420.                      show_depress(okay_gad,mapsize_window->RPort);
  421.                      Delay(10L);
  422.                      resize_flag = TRUE;
  423.                      goto exit_mapsize_window;
  424.                   case 'b':
  425.                      if ((qualifier & IEQUALIFIER_LCOMMAND)==0)
  426.                         break;
  427.                      show_depress(cancel_gad,mapsize_window->RPort);
  428.                      Delay(10L);
  429.                      goto exit_mapsize_window;
  430.                }
  431.             FI
  432.             if (class==IDCMP_GADGETUP) {
  433.                if (object==okay_gad) {
  434.                   resize_flag = TRUE;
  435.                   goto exit_mapsize_window;
  436.                FI
  437.                if (object==cancel_gad)
  438.                   goto exit_mapsize_window;
  439.             FI
  440.          OD
  441.       OD
  442.    }
  443.    exit_mapsize_window:
  444.  
  445.    {
  446.       // fetch new width, height, wrap values from the gadgets
  447.       LONG nwd = ((struct StringInfo *)(width_gad->SpecialInfo))->LongInt,
  448.            nht = ((struct StringInfo *)(height_gad->SpecialInfo))->LongInt;
  449.  
  450.       if (resize_flag)
  451.          wrap = (wrap_gad->Flags & GFLG_SELECTED);
  452.  
  453.       // now close up everything with the mapsize_window
  454.       CloseWindow(mapsize_window);
  455.       mapsize_window = NULL;
  456.       FreeGadgets(context);
  457.       ClearPointer(map_window);
  458.       ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  459.  
  460.       if (resize_flag) {
  461.          try_map_resize(nwd,nht);
  462.          xoffs = yoffs = 0;
  463.          update_scrollers();
  464.          ME_draw_map();
  465.       FI
  466.    }
  467. }
  468.  
  469. /*
  470.    This section is devoted to the terrain selection window, where the
  471.    user picks the kind of terrain he wants to draw with.
  472. */
  473.  
  474. int new_brush;
  475.  
  476. int terrain_index[] = {
  477.    HEX_PLAINS, HEX_DESERT, HEX_FORBID,
  478.    HEX_BRUSH, HEX_FOREST, HEX_JUNGLE,
  479.    HEX_RUGGED, HEX_HILLS, HEX_MOUNTAINS,
  480.    HEX_PEAKS, HEX_SWAMP, HEX_SHALLOWS,
  481.    HEX_OCEAN, HEX_DEPTH, HEX_ICE, HEX_CITY,
  482.    HEX_ROADS
  483. };
  484.  
  485. void new_terrain(x,y)
  486. int x,y;
  487. {  // activate the user's selection from the terrain_window
  488.    int col, row, newer_brush;
  489.  
  490.    row = (y-19)/24;
  491.    col = ((x-5)-(row%2)*15)/30;
  492.    newer_brush = terrain_index[row*8+col];
  493.  
  494.    highlight_terrain(new_brush,BLACK);
  495.    highlight_terrain(newer_brush,WHITE);
  496.    new_brush = newer_brush;
  497.    brush = new_brush;
  498. }
  499.  
  500. void highlight_terrain(terrain,color)
  501. int terrain, color;
  502. {  // outline the specified terrain type
  503.    int ctr;
  504.  
  505.    SetAPen(rast_port,color);
  506.    for (ctr = 0; ctr<=16; ctr++)
  507.       if (terrain==terrain_index[ctr])
  508.         px_outline_hex(5+30*ctr,15);
  509. }
  510.  
  511. void do_terrain_window()
  512. {  // everything for the terrain selection/info window
  513.   
  514.    struct Window *terrain_window = NULL;
  515.    struct Gadget *context, *info_gad, *ok_gad;
  516.    struct NewGadget generic = {
  517.       515,18,      // leftedge, topedge
  518.       66,12,   // width, height
  519.       "Okay",  // text label
  520.       NULL,    // font
  521.       3,       // gadget ID
  522.       NULL,NULL,NULL
  523.    };
  524.  
  525.    new_brush = brush;   // initial new_brush value
  526.    
  527.    // make sure user doesn't play with the map window now
  528.    SetPointer(map_window,BUSY_POINTER);
  529.    ModifyIDCMP(map_window,NULL);
  530.  
  531.    // create the gadgets
  532.    if (!CreateContext(&context))
  533.       clean_exit(1,"Unable to create context gadget!");
  534.    generic.ng_VisualInfo = vi;
  535.    generic.ng_TextAttr = &topaz11;
  536.    generic.ng_LeftEdge += 5;
  537.    generic.ng_GadgetText = "Info";
  538.    info_gad = CreateGadget(BUTTON_KIND,context,&generic,TAG_END);
  539.    generic.ng_TopEdge += 13;
  540.    generic.ng_GadgetText = "Ok";
  541.    ok_gad = CreateGadget(BUTTON_KIND,info_gad,&generic,TAG_END);
  542.    
  543.    // do the window itself
  544.    terrain_window = OpenWindowTags(NULL,
  545.       WA_Gadgets,context,
  546.       WA_Title,"Terrain",
  547.       WA_Top,335,    WA_Left,7,
  548.       WA_Width,612,  WA_Height,50,
  549.       WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY
  550.               |IDCMP_GADGETUP,
  551.       WA_Flags,NOCAREREFRESH|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_CLOSEGADGET,
  552.       WA_CustomScreen,map_screen,
  553.       TAG_END );
  554.    
  555.    if (terrain_window==NULL)
  556.       clean_exit(1,"ERROR: Unable to open terrain window!");
  557.    
  558.    INFO = FALSE;
  559.    
  560.    rast_port = terrain_window->RPort;
  561.  
  562.    {  // render the terrain hexes
  563.       int ctr;
  564.       
  565.       for (ctr = 0; ctr<=16; ctr++) {
  566.          SetAPen(rast_port,BLACK);
  567.          px_outline_hex(5+30*ctr,15);
  568.          if (terrain_index[ctr]<16)
  569.              px_plot_hex(5+30*ctr,15,terrain_index[ctr]);
  570.          else
  571.              px_plot_hex(5+30*ctr,15,HEX_PLAINS);
  572.          if (terrain_index[ctr]==17)
  573.              px_plot_hex(5+30*ctr,15,HEX_PLAINS);
  574.       OD
  575.      
  576.       // blit in the city
  577.       px_plot_city(463,24);
  578.       px_plot_roads(493,24);
  579.       
  580.       // highlight the current terrain
  581.       highlight_terrain(brush,WHITE);
  582.    }
  583.     
  584.  
  585.    {
  586.    
  587.       // handle the user actions here
  588.       struct IntuiMessage *message; // the message the IDCMP sends us
  589.       //struct MenuItem *item;
  590.       //int ctr;
  591.  
  592.       // useful for interpreting IDCMP messages
  593.       UWORD code;
  594.       ULONG class;
  595.       APTR object;
  596.  
  597.       while (TRUE) {
  598.          WaitPort(terrain_window->UserPort);
  599.          while (message = GT_GetIMsg(terrain_window->UserPort)) {
  600.             code = message->Code;  // MENUNUM
  601.             object = message->IAddress;  // Gadget
  602.             class = message->Class;
  603.             GT_ReplyIMsg(message);
  604.             if (class==MOUSEBUTTONS && code==SELECTDOWN)
  605.                new_terrain(message->MouseX,message->MouseY);
  606.             if (class==MOUSEBUTTONS && code==MIDDLEDOWN)
  607.                goto exit_terrain_window;
  608.             if (class==CLOSEWINDOW)
  609.                goto exit_terrain_window;
  610.             if (class==GADGETUP) {
  611.                if (object==info_gad) {
  612.                   //print("Found [INFO] button!\n");
  613.                   INFO = TRUE;
  614.                   goto exit_terrain_window;
  615.                FI
  616.                if (object==ok_gad) 
  617.                   goto exit_terrain_window;
  618.             FI
  619.             if (class==IDCMP_VANILLAKEY && code=='i'){
  620.                INFO = TRUE;
  621.                goto exit_terrain_window;
  622.             FI
  623.             if (class==IDCMP_VANILLAKEY && code==' ') {
  624.                //code = ' ';
  625.                goto exit_terrain_window;
  626.             FI
  627.                
  628.          OD
  629.       OD
  630.    }
  631.    exit_terrain_window:
  632.  
  633.    {  // set the MX menu items to reflect this change
  634.       struct MenuItem *item;
  635.       int ctr;
  636.  
  637.       item = ItemAddress(editor_menu_strip,FULLMENUNUM(1,2,0));
  638.       for (ctr = 1; ctr<=17; ctr++) {
  639.          if (ctr==brush)
  640.             item->Flags |= CHECKED;
  641.          else
  642.             item->Flags &= ~CHECKED;
  643.          item = item->NextItem;
  644.       OD
  645.    }
  646.  
  647.    // now clean everything up and leave
  648.        rast_port = map_window->RPort;
  649.        CloseWindow(terrain_window);
  650.        terrain_window = NULL;
  651.        FreeGadgets(context);
  652.        ClearPointer(map_window);
  653.        ModifyIDCMP(map_window,IDCMP_MAPEDIT);       
  654. }
  655.  
  656. void info_update_gadget(info_button)
  657. struct Gadget *info_button;
  658. {
  659.        int color, destx, desty;
  660.        int info_icon = info_button->GadgetID;
  661.        
  662.        destx = info_button->LeftEdge+1;
  663.        desty = info_button->TopEdge+1;
  664.        
  665.        switch (info_icon) {
  666.             case RIFLE:
  667.             case ARMOR:
  668.                 color = GREEN;
  669.                 break;
  670.             case AIRCAV:
  671.             case BOMBER:
  672.             case FIGHTER:
  673.                 color = LT_BLUE;
  674.                 break;
  675.             case TRANSPORT:
  676.             case SUB:
  677.             case DESTROYER:
  678.             case CRUISER:
  679.             case BATTLESHIP:
  680.             case CARRIER:
  681.                 color = DK_BLUE;
  682.                 break;
  683.             default:
  684.                 return;
  685.        };
  686.        px_plot_icon(info_icon,destx,desty,color,ORDER_NONE,FALSE);
  687.        if (infostatus[info_icon].enabled)
  688.             bevel_box(destx-1, desty-1, 21, 17,TRUE);
  689.        else {
  690.             SetAPen(rast_port,RED);
  691.             BltPattern(rast_port,(PLANEPTR)banned_mask,destx+1,desty+1,
  692.                 destx+17,desty+13,4);
  693.        FI
  694. }         
  695.  
  696. void do_info_window()
  697. {  // everything for the terrain info window
  698.    struct Window *info_window = NULL;
  699.   
  700.    struct Gadget *context, *info_inf, *info_arm, *info_cav, *info_bom, *info_ftr,
  701.                  *info_trn, *info_sub, *info_des, *info_cru, *info_bat,
  702.                  *info_car;
  703.    struct Gadget *ok_gad; 
  704.    struct NewGadget generic = {
  705.       515,25,      // leftedge, topedge
  706.       66,16,   // width, height
  707.       "Okay",  // text label
  708.       NULL,    // font
  709.       3,       // gadget ID
  710.       NULL,NULL,NULL
  711.    };
  712.    struct NewGadget info_button = {
  713.       150,45,
  714.       21,17,
  715.       NULL,
  716.       NULL,
  717.       RIFLE,
  718.       NULL,
  719.       NULL,
  720.       NULL,
  721.    }; 
  722.  
  723.    // make sure user doesn't play with the map window now
  724.    SetPointer(map_window,BUSY_POINTER);
  725.    ModifyIDCMP(map_window,NULL);
  726.  
  727.    // create the gadgets
  728.    if (!CreateContext(&context))
  729.       clean_exit(1,"Unable to create context gadget!");
  730.    info_button.ng_VisualInfo = vi;
  731.    info_inf = CreateGadget(GENERIC_KIND,context,&info_button,TAG_END);
  732.    info_inf->Flags |= GFLG_GADGHCOMP;
  733.    info_inf->Activation |= GACT_RELVERIFY;
  734.    
  735.    info_button.ng_LeftEdge = 180;
  736.    info_button.ng_GadgetID = ARMOR;
  737.    info_arm = CreateGadget(GENERIC_KIND,info_inf,&info_button,TAG_END);
  738.    info_arm->Flags |= GFLG_GADGHCOMP;
  739.    info_arm->Activation |= GACT_RELVERIFY;
  740.    
  741.    info_button.ng_LeftEdge = 210;
  742.    info_button.ng_GadgetID = AIRCAV;
  743.    info_cav = CreateGadget(GENERIC_KIND,info_arm,&info_button,TAG_END);
  744.    info_cav->Flags |= GFLG_GADGHCOMP;
  745.    info_cav->Activation |= GACT_RELVERIFY;
  746.  
  747.    info_button.ng_LeftEdge = 240;
  748.    info_button.ng_GadgetID = BOMBER;
  749.    info_bom = CreateGadget(GENERIC_KIND,info_cav,&info_button,TAG_END);
  750.    info_bom->Flags |= GFLG_GADGHCOMP;
  751.    info_bom->Activation |= GACT_RELVERIFY;
  752.      
  753.    info_button.ng_LeftEdge = 270;
  754.    info_button.ng_GadgetID = FIGHTER;
  755.    info_ftr = CreateGadget(GENERIC_KIND,info_bom,&info_button,TAG_END);
  756.    info_ftr->Flags |= GFLG_GADGHCOMP;
  757.    info_ftr->Activation |= GACT_RELVERIFY;
  758.       
  759.    info_button.ng_LeftEdge = 300;
  760.    info_button.ng_GadgetID = TRANSPORT;
  761.    info_trn = CreateGadget(GENERIC_KIND,info_ftr,&info_button,TAG_END);
  762.    info_trn->Flags |= GFLG_GADGHCOMP;
  763.    info_trn->Activation |= GACT_RELVERIFY;
  764.        
  765.    info_button.ng_LeftEdge = 330;
  766.    info_button.ng_GadgetID = SUB;
  767.    info_sub = CreateGadget(GENERIC_KIND,info_trn,&info_button,TAG_END);
  768.    info_sub->Flags |= GFLG_GADGHCOMP;
  769.    info_sub->Activation |= GACT_RELVERIFY;
  770.         
  771.    info_button.ng_LeftEdge = 360;
  772.    info_button.ng_GadgetID = DESTROYER;
  773.    info_des = CreateGadget(GENERIC_KIND,info_sub,&info_button,TAG_END);
  774.    info_des->Flags |= GFLG_GADGHCOMP;
  775.    info_des->Activation |= GACT_RELVERIFY;
  776.          
  777.    info_button.ng_LeftEdge = 390;
  778.    info_button.ng_GadgetID = CRUISER;
  779.    info_cru = CreateGadget(GENERIC_KIND,info_des,&info_button,TAG_END);
  780.    info_cru->Flags |= GFLG_GADGHCOMP;
  781.    info_cru->Activation |= GACT_RELVERIFY;
  782.           
  783.    info_button.ng_LeftEdge = 420;
  784.    info_button.ng_GadgetID = BATTLESHIP;
  785.    info_bat = CreateGadget(GENERIC_KIND,info_cru,&info_button,TAG_END);
  786.    info_bat->Flags |= GFLG_GADGHCOMP;
  787.    info_bat->Activation |= GACT_RELVERIFY;
  788.            
  789.    info_button.ng_LeftEdge = 450;
  790.    info_button.ng_GadgetID = CARRIER;
  791.    info_car = CreateGadget(GENERIC_KIND,info_bat,&info_button,TAG_END);
  792.    info_car->Flags |= GFLG_GADGHCOMP;
  793.    info_car->Activation |= GACT_RELVERIFY;
  794.    generic.ng_VisualInfo = vi;
  795.    generic.ng_TextAttr = &topaz11;
  796.    generic.ng_LeftEdge += 25;
  797.    generic.ng_GadgetText = "OK";
  798.    ok_gad = CreateGadget(BUTTON_KIND,info_car,&generic,TAG_END);
  799.  
  800.            
  801.  
  802.    // do the window itself
  803.    info_window = OpenWindowTags(NULL,
  804.       WA_Gadgets,context,
  805.       WA_Title,"Terrain Info",
  806.       WA_Top,100,    WA_Left,7,
  807.       WA_Width,612,  WA_Height,225,
  808.       WA_IDCMP,IDCMP_VANILLAKEY|IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_GADGETUP|IDCMP_GADGETDOWN,
  809.       WA_Flags,NOCAREREFRESH|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_CLOSEGADGET,
  810.       WA_CustomScreen,map_screen,
  811.       TAG_END );
  812.    if (info_window==NULL)
  813.       clean_exit(1,"ERROR: Unable to open info window!");
  814.    rast_port = info_window->RPort;
  815.  
  816.    {  // render the terrain hex
  817.       int ctr;
  818.       static int strength[] = { 1, 1, 1, 2, 1, 1, 3, 1, 2, 3, 1, 1 };
  819.       new_brush = brush;  
  820.       
  821.       if (new_brush != HEX_CITY) {
  822.          SetAPen(rast_port,BLACK);
  823.          px_outline_hex(5+25,15);
  824.          px_plot_hex(5+25,15,new_brush);
  825.       FI
  826.       // blit in the city
  827.       if (new_brush == HEX_CITY) {
  828.          SetAPen(rast_port,BLACK);
  829.          px_outline_hex(5+25,15);
  830.          px_plot_hex(5+25,15,HEX_PLAINS);
  831.          px_plot_city(37,23);
  832.       FI
  833.       
  834.       infostatus[RIFLE].enabled = FALSE;
  835.       info_update_gadget(info_inf);
  836.       //bevel_frame(176,46,29,23,FALSE);
  837.       infostatus[ARMOR].enabled = FALSE;
  838.       info_update_gadget(info_arm);
  839.       //bevel_frame(212,46,29,23,FALSE);
  840.       infostatus[AIRCAV].enabled = FALSE;
  841.       info_update_gadget(info_cav);
  842.       //bevel_frame(248,46,29,23,FALSE);
  843.       infostatus[BOMBER].enabled = FALSE;
  844.       info_update_gadget(info_bom);
  845.       //bevel_frame(284,46,29,23,FALSE);
  846.       infostatus[FIGHTER].enabled = FALSE;
  847.       info_update_gadget(info_ftr);
  848.       //bevel_frame(320,46,29,23,FALSE);
  849.       infostatus[TRANSPORT].enabled = FALSE;
  850.       info_update_gadget(info_trn);
  851.       //bevel_frame(356,46,29,23,FALSE);
  852.       infostatus[SUB].enabled = FALSE;
  853.       info_update_gadget(info_sub);
  854.       //bevel_frame(392,46,29,23,FALSE);
  855.       infostatus[DESTROYER].enabled = FALSE;
  856.       info_update_gadget(info_des);
  857.       //bevel_frame(428,46,29,23,FALSE);
  858.       infostatus[CRUISER].enabled = FALSE;
  859.       info_update_gadget(info_cru);
  860.       //bevel_frame(464,46,29,23,FALSE);
  861.       infostatus[BATTLESHIP].enabled = FALSE;
  862.       info_update_gadget(info_bat);
  863.       //bevel_frame(500,46,29,23,FALSE);
  864.       infostatus[CARRIER].enabled = FALSE;
  865.       info_update_gadget(info_car);
  866.       //bevel_frame(536,46,29,23,FALSE);
  867.                 
  868.       // render in some text and unit icons        
  869.          sprintf(foo,"Units able to traverse this terrain:");
  870.          plot_text(5+65,26,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  871.          sprintf(foo,"Movement Costs:");
  872.          plot_text(5+5,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  873.          bevel_box(138,67,370,36,FALSE);
  874.          bevel_box(138,105,370,111,TRUE);
  875.          sprintf(foo,"Defense Factors:");
  876.          plot_text(5+5,90,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  877.          sprintf(foo,"Movement Range:");
  878.          plot_text(5+5,110,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  879.          sprintf(foo,"Movement Speed:");
  880.          plot_text(5+5,130,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  881.          sprintf(foo,"Hitpoints:");
  882.          plot_text(5+5,150,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  883.          sprintf(foo,"Strength:");
  884.          plot_text(5+5,170,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  885.          
  886.          if (new_brush == HEX_FORBID) {
  887.             SetWindowTitles(info_window,"Forbidden Zone",(UBYTE *)~0);
  888.             //for (ctr=0; ctr <=10; ctr++) { 
  889.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  890.                 //sprintf(foo,"%ld",movement_cost_table[ctr][3]);
  891.                 //if (movement_cost_table[ctr][3] == -1)
  892.                 //    sprintf(foo," - ");
  893.                 //plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  894.                 //if (wishbook[ctr].range == -1) 
  895.                 //    sprintf(foo," - ");
  896.                 //else
  897.                 //    sprintf(foo,"%ld",wishbook[ctr].range);
  898.                 //plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  899.                 //sprintf(foo,"%ld",wishbook[ctr].speed);
  900.                 //plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  901.                 
  902.                 //sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  903.                 //plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  904.                 //sprintf(foo,"%ld",strength[ctr]);
  905.                 //plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  906.             //OD
  907.          FI
  908.  
  909.          if (new_brush == HEX_PLAINS) { 
  910.             SetWindowTitles(info_window,"Plains",(UBYTE *)~0);
  911.             infostatus[RIFLE].enabled = TRUE;
  912.             info_update_gadget(info_inf);
  913.             infostatus[ARMOR].enabled = TRUE;
  914.             info_update_gadget(info_arm);
  915.             infostatus[AIRCAV].enabled = TRUE;
  916.             info_update_gadget(info_cav);
  917.             infostatus[BOMBER].enabled = TRUE;
  918.             info_update_gadget(info_bom);
  919.             infostatus[FIGHTER].enabled = TRUE;
  920.             info_update_gadget(info_ftr);
  921.             for (ctr=0; ctr <=10; ctr++) { 
  922.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  923.                 sprintf(foo,"%ld",movement_cost_table[ctr][2]);
  924.                 if (movement_cost_table[ctr][2] == -1)
  925.                     sprintf(foo," - ");
  926.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  927.                 
  928.                 if (wishbook[ctr].range == -1) 
  929.                     sprintf(foo," - ");
  930.                 else
  931.                     sprintf(foo,"%ld",wishbook[ctr].range);
  932.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  933.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  934.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  935.                 
  936.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  937.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  938.                 sprintf(foo,"%ld",strength[ctr]);
  939.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  940.             OD
  941.          FI
  942.          if (new_brush == HEX_DESERT) {
  943.             SetWindowTitles(info_window,"Desert",(UBYTE *)~0);
  944.             infostatus[RIFLE].enabled = TRUE;
  945.             info_update_gadget(info_inf);
  946.             infostatus[ARMOR].enabled = TRUE;
  947.             info_update_gadget(info_arm);
  948.             infostatus[AIRCAV].enabled = TRUE;
  949.             info_update_gadget(info_cav);
  950.             infostatus[BOMBER].enabled = TRUE;
  951.             info_update_gadget(info_bom);
  952.             infostatus[FIGHTER].enabled = TRUE;
  953.             info_update_gadget(info_ftr);
  954.  
  955.             for (ctr=0; ctr <=10; ctr++) { 
  956.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  957.                 sprintf(foo,"%ld",movement_cost_table[ctr][3]);
  958.                 if (movement_cost_table[ctr][3] == -1)
  959.                     sprintf(foo," - ");
  960.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  961.                 if (wishbook[ctr].range == -1) 
  962.                     sprintf(foo," - ");
  963.                 else
  964.                     sprintf(foo,"%ld",wishbook[ctr].range);
  965.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  966.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  967.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  968.                 
  969.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  970.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  971.                 sprintf(foo,"%ld",strength[ctr]);
  972.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);            
  973.             OD
  974.          FI
  975.          if (new_brush == HEX_BRUSH) {
  976.             SetWindowTitles(info_window,"Scrubland",(UBYTE *)~0);
  977.             infostatus[RIFLE].enabled = TRUE;
  978.             info_update_gadget(info_inf);
  979.             infostatus[ARMOR].enabled = TRUE;
  980.             info_update_gadget(info_arm);
  981.             infostatus[AIRCAV].enabled = TRUE;
  982.             info_update_gadget(info_cav);
  983.             infostatus[BOMBER].enabled = TRUE;
  984.             info_update_gadget(info_bom);
  985.             infostatus[FIGHTER].enabled = TRUE;
  986.             info_update_gadget(info_ftr);
  987.  
  988.             for (ctr=0; ctr <=10; ctr++) { 
  989.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  990.                 sprintf(foo,"%ld",movement_cost_table[ctr][4]);
  991.                 if (movement_cost_table[ctr][4] == -1)
  992.                     sprintf(foo," - ");
  993.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  994.                 if (wishbook[ctr].range == -1) 
  995.                     sprintf(foo," - ");
  996.                 else
  997.                     sprintf(foo,"%ld",wishbook[ctr].range);
  998.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  999.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1000.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1001.                 
  1002.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1003.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1004.                 sprintf(foo,"%ld",strength[ctr]);
  1005.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1006.             OD
  1007.          FI
  1008.          if (new_brush == HEX_FOREST) {
  1009.             SetWindowTitles(info_window,"Forest",(UBYTE *)~0);
  1010.             infostatus[RIFLE].enabled = TRUE;
  1011.             info_update_gadget(info_inf);
  1012.             infostatus[ARMOR].enabled = TRUE;
  1013.             info_update_gadget(info_arm);
  1014.             infostatus[AIRCAV].enabled = TRUE;
  1015.             info_update_gadget(info_cav);
  1016.             infostatus[BOMBER].enabled = TRUE;
  1017.             info_update_gadget(info_bom);
  1018.             infostatus[FIGHTER].enabled = TRUE;
  1019.             info_update_gadget(info_ftr);
  1020.  
  1021.             for (ctr=0; ctr <=10; ctr++) { 
  1022.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1023.                 sprintf(foo,"%ld",movement_cost_table[ctr][5]);
  1024.                 if (movement_cost_table[ctr][5] == -1)
  1025.                     sprintf(foo," - ");
  1026.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1027.                 if (wishbook[ctr].range == -1) 
  1028.                     sprintf(foo," - ");
  1029.                 else
  1030.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1031.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1032.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1033.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1034.                 
  1035.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1036.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1037.                 sprintf(foo,"%ld",strength[ctr]);
  1038.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1039.             OD
  1040.          FI
  1041.          if (new_brush == HEX_JUNGLE) {
  1042.             SetWindowTitles(info_window,"Jungle",(UBYTE *)~0);
  1043.             infostatus[RIFLE].enabled = TRUE;
  1044.             info_update_gadget(info_inf);
  1045.             infostatus[ARMOR].enabled = TRUE;
  1046.             info_update_gadget(info_arm);
  1047.             infostatus[AIRCAV].enabled = TRUE;
  1048.             info_update_gadget(info_cav);
  1049.             infostatus[BOMBER].enabled = TRUE;
  1050.             info_update_gadget(info_bom);
  1051.             infostatus[FIGHTER].enabled = TRUE;
  1052.             info_update_gadget(info_ftr);
  1053.  
  1054.             for (ctr=0; ctr <=10; ctr++) { 
  1055.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1056.                 sprintf(foo,"%ld",movement_cost_table[ctr][6]);
  1057.                 if (movement_cost_table[ctr][6] == -1)
  1058.                     sprintf(foo," - ");
  1059.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1060.                 if (wishbook[ctr].range == -1) 
  1061.                     sprintf(foo," - ");
  1062.                 else
  1063.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1064.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1065.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1066.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1067.                 
  1068.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1069.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1070.                 sprintf(foo,"%ld",strength[ctr]);
  1071.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1072.             OD
  1073.          FI
  1074.          if (new_brush == HEX_RUGGED) {
  1075.             SetWindowTitles(info_window,"Rugged",(UBYTE *)~0);
  1076.             infostatus[RIFLE].enabled = TRUE;
  1077.             info_update_gadget(info_inf);
  1078.             infostatus[ARMOR].enabled = TRUE;
  1079.             info_update_gadget(info_arm);
  1080.             infostatus[AIRCAV].enabled = TRUE;
  1081.             info_update_gadget(info_cav);
  1082.             infostatus[BOMBER].enabled = TRUE;
  1083.             info_update_gadget(info_bom);
  1084.             infostatus[FIGHTER].enabled = TRUE;
  1085.             info_update_gadget(info_ftr);
  1086.  
  1087.             for (ctr=0; ctr <=10; ctr++) { 
  1088.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1089.                 sprintf(foo,"%ld",movement_cost_table[ctr][7]);
  1090.                 if (movement_cost_table[ctr][7] == -1)
  1091.                     sprintf(foo," - ");
  1092.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1093.                 if (wishbook[ctr].range == -1) 
  1094.                     sprintf(foo," - ");
  1095.                 else
  1096.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1097.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1098.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1099.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1100.                 
  1101.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1102.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1103.                 sprintf(foo,"%ld",strength[ctr]);
  1104.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1105.             OD
  1106.          FI
  1107.          if (new_brush == HEX_HILLS) {
  1108.             SetWindowTitles(info_window,"Hills",(UBYTE *)~0);
  1109.             infostatus[RIFLE].enabled = TRUE;
  1110.             info_update_gadget(info_inf);
  1111.             infostatus[ARMOR].enabled = TRUE;
  1112.             info_update_gadget(info_arm);
  1113.             infostatus[AIRCAV].enabled = TRUE;
  1114.             info_update_gadget(info_cav);
  1115.             infostatus[BOMBER].enabled = TRUE;
  1116.             info_update_gadget(info_bom);
  1117.             infostatus[FIGHTER].enabled = TRUE;
  1118.             info_update_gadget(info_ftr);
  1119.  
  1120.             for (ctr=0; ctr <=10; ctr++) { 
  1121.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1122.                 sprintf(foo,"%ld",movement_cost_table[ctr][8]);
  1123.                 if (movement_cost_table[ctr][8] == -1)
  1124.                     sprintf(foo," - ");
  1125.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1126.                 if (wishbook[ctr].range == -1) 
  1127.                     sprintf(foo," - ");
  1128.                 else
  1129.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1130.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1131.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1132.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1133.                 
  1134.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1135.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1136.                 sprintf(foo,"%ld",strength[ctr]);
  1137.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1138.             OD
  1139.          FI
  1140.          if (new_brush == HEX_MOUNTAINS) {
  1141.             SetWindowTitles(info_window,"Mountains",(UBYTE *)~0);
  1142.             infostatus[RIFLE].enabled = TRUE;
  1143.             info_update_gadget(info_inf);
  1144.             infostatus[ARMOR].enabled = TRUE;
  1145.             info_update_gadget(info_arm);
  1146.             infostatus[AIRCAV].enabled = TRUE;
  1147.             info_update_gadget(info_cav);
  1148.             infostatus[BOMBER].enabled = TRUE;
  1149.             info_update_gadget(info_bom);
  1150.             infostatus[FIGHTER].enabled = TRUE;
  1151.             info_update_gadget(info_ftr);
  1152.  
  1153.             for (ctr=0; ctr <=10; ctr++) { 
  1154.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1155.                 sprintf(foo,"%ld",movement_cost_table[ctr][9]);
  1156.                 if (movement_cost_table[ctr][9] == -1)
  1157.                     sprintf(foo," - ");
  1158.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1159.                 if (wishbook[ctr].range == -1) 
  1160.                     sprintf(foo," - ");
  1161.                 else
  1162.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1163.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1164.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1165.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1166.                 
  1167.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1168.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1169.                 sprintf(foo,"%ld",strength[ctr]);
  1170.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1171.             OD
  1172.          FI
  1173.          if (new_brush == HEX_PEAKS) {
  1174.             SetWindowTitles(info_window,"Mountain Peaks",(UBYTE *)~0);
  1175.             infostatus[BOMBER].enabled = TRUE;
  1176.             info_update_gadget(info_bom);
  1177.             infostatus[FIGHTER].enabled = TRUE;
  1178.             info_update_gadget(info_ftr);
  1179.  
  1180.             for (ctr=0; ctr <=10; ctr++) { 
  1181.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1182.                 sprintf(foo,"%ld",movement_cost_table[ctr][10]);
  1183.                 if (movement_cost_table[ctr][10] == -1)
  1184.                     sprintf(foo," - ");
  1185.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1186.                 if (wishbook[ctr].range == -1) 
  1187.                     sprintf(foo," - ");
  1188.                 else
  1189.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1190.                 if (ctr==2)
  1191.                     sprintf(foo," - ");
  1192.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1193.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1194.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1195.                 
  1196.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1197.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1198.                 sprintf(foo,"%ld",strength[ctr]);
  1199.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1200.             OD
  1201.          FI
  1202.          if (new_brush == HEX_SWAMP) {
  1203.             SetWindowTitles(info_window,"Swamp",(UBYTE *)~0);
  1204.             infostatus[RIFLE].enabled = TRUE;
  1205.             info_update_gadget(info_inf);
  1206.             infostatus[ARMOR].enabled = TRUE;
  1207.             info_update_gadget(info_arm);
  1208.             infostatus[AIRCAV].enabled = TRUE;
  1209.             info_update_gadget(info_cav);
  1210.             infostatus[BOMBER].enabled = TRUE;
  1211.             info_update_gadget(info_bom);
  1212.             infostatus[FIGHTER].enabled = TRUE;
  1213.             info_update_gadget(info_ftr);
  1214.  
  1215.             for (ctr=0; ctr <=10; ctr++) { 
  1216.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1217.                 sprintf(foo,"%ld",movement_cost_table[ctr][11]);
  1218.                 if (movement_cost_table[ctr][11] == -1)
  1219.                     sprintf(foo," - ");
  1220.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1221.                 if (wishbook[ctr].range == -1) 
  1222.                     sprintf(foo," - ");
  1223.                 else
  1224.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1225.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1226.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1227.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1228.                 
  1229.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1230.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1231.                 sprintf(foo,"%ld",strength[ctr]);
  1232.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1233.             OD
  1234.          FI
  1235.          
  1236.          if (new_brush == HEX_SHALLOWS) {
  1237.             SetWindowTitles(info_window,"Shallow Waters",(UBYTE *)~0);
  1238.             infostatus[AIRCAV].enabled = TRUE;
  1239.             info_update_gadget(info_cav);
  1240.             infostatus[BOMBER].enabled = TRUE;
  1241.             info_update_gadget(info_bom);
  1242.             infostatus[FIGHTER].enabled = TRUE;
  1243.             info_update_gadget(info_ftr);
  1244.             infostatus[AIRCAV].enabled = TRUE;
  1245.             info_update_gadget(info_cav);
  1246.             infostatus[BOMBER].enabled = TRUE;
  1247.             info_update_gadget(info_bom);
  1248.             infostatus[FIGHTER].enabled = TRUE;
  1249.             info_update_gadget(info_ftr);
  1250.             infostatus[TRANSPORT].enabled = TRUE;
  1251.             info_update_gadget(info_trn);
  1252.             infostatus[SUB].enabled = TRUE;
  1253.             info_update_gadget(info_sub);
  1254.             infostatus[DESTROYER].enabled = TRUE;
  1255.             info_update_gadget(info_des);
  1256.             infostatus[CRUISER].enabled = TRUE;
  1257.             info_update_gadget(info_cru);
  1258.             infostatus[BATTLESHIP].enabled = TRUE;
  1259.             info_update_gadget(info_bat);
  1260.             infostatus[CARRIER].enabled = TRUE;
  1261.             info_update_gadget(info_car);
  1262.  
  1263.             for (ctr=0; ctr <=10; ctr++) { 
  1264.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1265.                 sprintf(foo,"%ld",movement_cost_table[ctr][12]);
  1266.                 if (movement_cost_table[ctr][12] == -1)
  1267.                     sprintf(foo," - ");
  1268.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1269.                 if (wishbook[ctr].range == -1) 
  1270.                     sprintf(foo," - ");
  1271.                 else
  1272.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1273.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1274.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1275.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1276.                 
  1277.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1278.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1279.                 sprintf(foo,"%ld",strength[ctr]);
  1280.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1281.             OD
  1282.          FI
  1283.          
  1284.          if (new_brush == HEX_OCEAN) {
  1285.             SetWindowTitles(info_window,"Ocean",(UBYTE *)~0);
  1286.             infostatus[AIRCAV].enabled = TRUE;
  1287.             info_update_gadget(info_cav);
  1288.             infostatus[BOMBER].enabled = TRUE;
  1289.             info_update_gadget(info_bom);
  1290.             infostatus[FIGHTER].enabled = TRUE;
  1291.             info_update_gadget(info_ftr);
  1292.             infostatus[TRANSPORT].enabled = TRUE;
  1293.             info_update_gadget(info_trn);
  1294.             infostatus[SUB].enabled = TRUE;
  1295.             info_update_gadget(info_sub);
  1296.             infostatus[DESTROYER].enabled = TRUE;
  1297.             info_update_gadget(info_des);
  1298.             infostatus[CRUISER].enabled = TRUE;
  1299.             info_update_gadget(info_cru);
  1300.             infostatus[BATTLESHIP].enabled = TRUE;
  1301.             info_update_gadget(info_bat);
  1302.             infostatus[CARRIER].enabled = TRUE;
  1303.             info_update_gadget(info_car);
  1304.  
  1305.             for (ctr=0; ctr <=10; ctr++) { 
  1306.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1307.                 sprintf(foo,"%ld",movement_cost_table[ctr][13]);
  1308.                 if (movement_cost_table[ctr][13] == -1)
  1309.                     sprintf(foo," - ");
  1310.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1311.                 if (wishbook[ctr].range == -1) 
  1312.                     sprintf(foo," - ");
  1313.                 else
  1314.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1315.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1316.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1317.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1318.                 
  1319.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1320.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1321.                 sprintf(foo,"%ld",strength[ctr]);
  1322.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1323.             OD
  1324.          FI
  1325.          
  1326.          if (new_brush == HEX_DEPTH) {
  1327.             SetWindowTitles(info_window,"Deep Ocean",(UBYTE *)~0);
  1328.             infostatus[AIRCAV].enabled = TRUE;
  1329.             info_update_gadget(info_cav);
  1330.             infostatus[BOMBER].enabled = TRUE;
  1331.             info_update_gadget(info_bom);
  1332.             infostatus[FIGHTER].enabled = TRUE;
  1333.             info_update_gadget(info_ftr);
  1334.             infostatus[TRANSPORT].enabled = TRUE;
  1335.             info_update_gadget(info_trn);
  1336.             infostatus[SUB].enabled = TRUE;
  1337.             info_update_gadget(info_sub);
  1338.             infostatus[DESTROYER].enabled = TRUE;
  1339.             info_update_gadget(info_des);
  1340.             infostatus[CRUISER].enabled = TRUE;
  1341.             info_update_gadget(info_cru);
  1342.             infostatus[BATTLESHIP].enabled = TRUE;
  1343.             info_update_gadget(info_bat);
  1344.             infostatus[CARRIER].enabled = TRUE;
  1345.             info_update_gadget(info_car);
  1346.  
  1347.             for (ctr=0; ctr <=10; ctr++) { 
  1348.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1349.                 sprintf(foo,"%ld",movement_cost_table[ctr][14]);
  1350.                 if (movement_cost_table[ctr][14] == -1)
  1351.                     sprintf(foo," - ");
  1352.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1353.                 if (wishbook[ctr].range == -1) 
  1354.                     sprintf(foo," - ");
  1355.                 else
  1356.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1357.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1358.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1359.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1360.                 
  1361.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1362.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1363.                 sprintf(foo,"%ld",strength[ctr]);
  1364.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1365.             OD
  1366.          FI
  1367.          
  1368.          if (new_brush == HEX_ICE) {
  1369.             SetWindowTitles(info_window,"Packed Ice",(UBYTE *)~0);
  1370.             infostatus[AIRCAV].enabled = TRUE;
  1371.             info_update_gadget(info_cav);
  1372.             infostatus[BOMBER].enabled = TRUE;
  1373.             info_update_gadget(info_bom);
  1374.             infostatus[FIGHTER].enabled = TRUE;
  1375.             info_update_gadget(info_ftr);
  1376.  
  1377.             for (ctr=0; ctr <=10; ctr++) { 
  1378.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1379.                 sprintf(foo,"%ld",movement_cost_table[ctr][15]);
  1380.                 if (movement_cost_table[ctr][15] == -1)
  1381.                     sprintf(foo," - ");
  1382.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1383.                 if (wishbook[ctr].range == -1) 
  1384.                     sprintf(foo," - ");
  1385.                 else
  1386.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1387.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1388.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1389.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1390.                 
  1391.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1392.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1393.                 sprintf(foo,"%ld",strength[ctr]);
  1394.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1395.             OD
  1396.          FI
  1397.          
  1398.          if (new_brush == HEX_CITY) {
  1399.             SetWindowTitles(info_window,"City",(UBYTE *)~0);
  1400.             infostatus[RIFLE].enabled = TRUE;
  1401.             info_update_gadget(info_inf);
  1402.             infostatus[ARMOR].enabled = TRUE;
  1403.             info_update_gadget(info_arm);
  1404.             infostatus[AIRCAV].enabled = TRUE;
  1405.             info_update_gadget(info_cav);
  1406.             infostatus[BOMBER].enabled = TRUE;
  1407.             info_update_gadget(info_bom);
  1408.             infostatus[FIGHTER].enabled = TRUE;
  1409.             info_update_gadget(info_ftr);
  1410.             infostatus[TRANSPORT].enabled = TRUE;
  1411.             info_update_gadget(info_trn);
  1412.             infostatus[SUB].enabled = TRUE;
  1413.             info_update_gadget(info_sub);
  1414.             infostatus[DESTROYER].enabled = TRUE;
  1415.             info_update_gadget(info_des);
  1416.             infostatus[CRUISER].enabled = TRUE;
  1417.             info_update_gadget(info_cru);
  1418.             infostatus[BATTLESHIP].enabled = TRUE;
  1419.             info_update_gadget(info_bat);
  1420.             infostatus[CARRIER].enabled = TRUE;
  1421.             info_update_gadget(info_car);
  1422.  
  1423.             for (ctr=0; ctr <=10; ctr++) { 
  1424.                 //px_plot_icon(ctr,150+30*ctr,50,BLACK,0,FALSE);
  1425.                 sprintf(foo," 10");
  1426.                 //if (movement_cost_table[ctr][1] == -1)
  1427.                 //    sprintf(foo," - ");
  1428.                 plot_text(150+30*ctr,70,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1429.                 if (wishbook[ctr].range == -1) 
  1430.                     sprintf(foo," - ");
  1431.                 else
  1432.                     sprintf(foo,"%ld",wishbook[ctr].range);
  1433.                 plot_text(150+30*ctr,110,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1434.                 sprintf(foo,"%ld",wishbook[ctr].speed);
  1435.                 plot_text(150+30*ctr,130,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1436.                 
  1437.                 sprintf(foo,"%ld",wishbook[ctr].hitpoints);
  1438.                 plot_text(150+30*ctr,150,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1439.                 sprintf(foo,"%ld",strength[ctr]);
  1440.                 plot_text(150+30*ctr,170,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1441.             OD
  1442.          FI
  1443.                
  1444.    }
  1445.  
  1446.    {  // handle the user actions here
  1447.       struct IntuiMessage *message; // the message the IDCMP sends us
  1448.       
  1449.       // useful for interpreting IDCMP messages
  1450.       UWORD code;
  1451.       ULONG class;
  1452.       APTR object;
  1453.  
  1454.       while (TRUE) {
  1455.          WaitPort(info_window->UserPort);
  1456.          while (message = GT_GetIMsg(info_window->UserPort)) {
  1457.             code = message->Code;  // MENUNUM
  1458.             object = message->IAddress;  // Gadget
  1459.             class = message->Class;
  1460.             GT_ReplyIMsg(message);
  1461.             if (class==GADGETUP) {
  1462.                if (object==ok_gad) {
  1463.                   INFO = FALSE;
  1464.                   goto exit_info_window;
  1465.                FI 
  1466.                if (object==info_inf) 
  1467.                   alert(info_window,NULL,"For future use.","Okay");
  1468.                if (object==info_arm) 
  1469.                   alert(info_window,NULL,"For future use.","Okay");
  1470.                if (object==info_cav) 
  1471.                   alert(info_window,NULL,"For future use.","Okay");
  1472.                if (object==info_bom) 
  1473.                   alert(info_window,NULL,"For future use.","Okay");
  1474.                if (object==info_ftr) 
  1475.                   alert(info_window,NULL,"For future use.","Okay");
  1476.                if (object==info_trn) 
  1477.                   alert(info_window,NULL,"For future use.","Okay");
  1478.                if (object==info_sub) 
  1479.                   alert(info_window,NULL,"For future use.","Okay");
  1480.                if (object==info_des) 
  1481.                   alert(info_window,NULL,"For future use.","Okay");
  1482.                if (object==info_cru) 
  1483.                   alert(info_window,NULL,"For future use.","Okay");
  1484.                if (object==info_bat) 
  1485.                   alert(info_window,NULL,"For future use.","Okay");
  1486.                if (object==info_car) 
  1487.                   alert(info_window,NULL,"For future use.","Okay");
  1488.         
  1489.             FI
  1490.             if (class==CLOSEWINDOW) {
  1491.                INFO = FALSE; 
  1492.                goto exit_info_window;
  1493.             FI
  1494.             if (class==IDCMP_VANILLAKEY && code==13) {
  1495.                INFO = FALSE;
  1496.                goto exit_info_window;
  1497.             FI
  1498.          OD
  1499.       OD
  1500.    }
  1501.    exit_info_window:
  1502.  
  1503.  
  1504.    // now clean everything up and leave
  1505.        rast_port = map_window->RPort;
  1506.        CloseWindow(info_window);
  1507.        info_window = NULL;
  1508.        FreeGadgets(context);
  1509.        ClearPointer(map_window);
  1510.        ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  1511. }
  1512.  
  1513. #define MYGAD_SLIDER    (0)
  1514. #define MYGAD_SLIDER2   (1)
  1515. #define MYGAD_SLIDER3   (2)
  1516. #define MYGAD_SLIDER4   (3)
  1517. #define MYGAD_SLIDER5   (4)
  1518. #define MYGAD_SLIDER6   (5)
  1519. #define MYGAD_SLIDER7   (6)
  1520. #define MYGAD_SLIDER8   (7)
  1521. #define MYGAD_SLIDER9   (8)
  1522. #define MYGAD_SLIDER10  (9)
  1523. #define MYGAD_SLIDER11  (10)
  1524. #define MYGAD_SLIDER12  (11)
  1525. #define MYGAD_SLIDER13  (12)
  1526. #define MYGAD_SLIDER14  (13)
  1527. #define MYGAD_SLIDER15  (14)
  1528. #define MYGAD_SLIDER16  (15)
  1529. #define MYGAD_BUTTON    (16)
  1530. #define MYGAD_BUTTON2   (17)
  1531. #define MYGAD_BUTTON3   (18)
  1532.     
  1533. #define SLIDER_MIN  (0)
  1534. #define SLIDER_MAX  (100)
  1535.  
  1536.  
  1537. VOID handleGadgetEvent(struct Window *mywin, struct Gadget *gad, UWORD code,
  1538.     WORD *slider_level, struct Gadget *my_gads[])
  1539. {
  1540.     
  1541.     int ctr;
  1542.  
  1543.     terminated = FALSE;
  1544.                                    
  1545.         switch (gad->GadgetID)
  1546.         {
  1547.             //static int tot_hex;
  1548.            
  1549.                 case MYGAD_SLIDER:
  1550.                     *slider_level = code;
  1551.                     sprintf(foo,"%ld ",code);
  1552.                     plot_text(5+5,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1553.                     figctr[0] = code;
  1554.                     break;
  1555.                 case MYGAD_SLIDER2:
  1556.                     *slider_level = code;
  1557.                     sprintf(foo,"%ld ",code);
  1558.                     plot_text(5+35,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1559.                     figctr[1] = code;
  1560.                     break;
  1561.                 case MYGAD_SLIDER3:
  1562.                     *slider_level = code;
  1563.                     sprintf(foo,"%ld ",code);
  1564.                     plot_text(5+65,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1565.                     figctr[2] = code;
  1566.                     break;
  1567.                 case MYGAD_SLIDER4:
  1568.                     *slider_level = code;
  1569.                     sprintf(foo,"%ld ",code);
  1570.                     plot_text(5+95,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1571.                     figctr[3] = code;
  1572.                     break;
  1573.                 case MYGAD_SLIDER5:
  1574.                     *slider_level = code;
  1575.                     sprintf(foo,"%ld ",code);
  1576.                     plot_text(5+125,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1577.                     figctr[4] = code;
  1578.                     break;
  1579.                 case MYGAD_SLIDER6:
  1580.                     *slider_level = code;
  1581.                     sprintf(foo,"%ld ",code);
  1582.                     plot_text(5+155,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1583.                     figctr[5] = code;
  1584.                     break;
  1585.                 case MYGAD_SLIDER7:
  1586.                     *slider_level = code;
  1587.                     sprintf(foo,"%ld ",code);
  1588.                     plot_text(5+185,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1589.                     figctr[6] = code;
  1590.                     break;
  1591.                 case MYGAD_SLIDER8:
  1592.                     *slider_level = code;
  1593.                     sprintf(foo,"%ld ",code);
  1594.                     plot_text(5+215,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1595.                     figctr[7] = code;
  1596.                     break;
  1597.                 case MYGAD_SLIDER9:
  1598.                     *slider_level = code;
  1599.                     sprintf(foo,"%ld ",code);
  1600.                     plot_text(5+245,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1601.                     figctr[8] = code;
  1602.                     break;
  1603.                 case MYGAD_SLIDER10:
  1604.                     *slider_level = code;
  1605.                     sprintf(foo,"%ld ",code);
  1606.                     plot_text(5+275,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1607.                     figctr[9] = code;
  1608.                     break;
  1609.                 case MYGAD_SLIDER11:
  1610.                     *slider_level = code;
  1611.                     sprintf(foo,"%ld ",code);
  1612.                     plot_text(5+305,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1613.                     figctr[10] = code;
  1614.                     break;
  1615.                 case MYGAD_SLIDER12:
  1616.                     *slider_level = code;
  1617.                     sprintf(foo,"%ld ",code);
  1618.                     plot_text(5+335,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1619.                     figctr[11] = code;
  1620.                     break;
  1621.                 case MYGAD_SLIDER13:
  1622.                     *slider_level = code;
  1623.                     sprintf(foo,"%ld ",code);
  1624.                     plot_text(5+365,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1625.                     figctr[12] = code;
  1626.                     break;
  1627.                 case MYGAD_SLIDER14:
  1628.                     *slider_level = code;
  1629.                     sprintf(foo,"%ld ",code);
  1630.                     plot_text(5+395,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1631.                     figctr[13] = code;
  1632.                     break;
  1633.                 case MYGAD_SLIDER15:
  1634.                     *slider_level = code;
  1635.                     sprintf(foo,"%ld ",code);
  1636.                     plot_text(5+425,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1637.                     figctr[14] = code;
  1638.                     break;
  1639.                 case MYGAD_SLIDER16:
  1640.                     *slider_level = code;
  1641.                     sprintf(foo,"%ld ",code);
  1642.                     //plot_text(5+425,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1643.                     figctr[15] = code;
  1644.                     break;
  1645.                 case MYGAD_BUTTON:                   
  1646.                     //printf("Found Help Button.\n");
  1647.                     sprintf(foo,"The terrain sliders select the approximate\npercentage of terrain to be generated.\n\n");
  1648.                     strcat(foo,"The Generate button will generate the map\nand ask to sprinkle cities.\n\n");
  1649.                     strcat(foo,"The Presets button will create various\nenvironments.\n\n");
  1650.                     strcat(foo,"Closing the window cancels this option.");
  1651.                     alert(mywin,NULL,foo,"Okay");
  1652.                     for (ctr = 0; ctr<=14; ctr++) {
  1653.                         SetAPen(rast_port,BLACK);
  1654.                         px_outline_hex(5+30*ctr,15);
  1655.                         if (terrain_index[ctr]<16)
  1656.                             px_plot_hex(5+30*ctr,15,terrain_index[ctr]);
  1657.                     OD
  1658.                     
  1659.                     break;                     
  1660.                 case MYGAD_BUTTON2:
  1661.                     //printf("Found Generate Button.\n");
  1662.                     if (tot > 100) {
  1663.                         alert(mywin,NULL,"Map Terrain can't be over 100%! Please Adjust.","Okay");
  1664.                         //tot = 100;
  1665.                         frame(510,70,80,30,TRUE);
  1666.                         sprintf(foo,"TOTAL");
  1667.                         plot_text(530,66,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  1668.                         break;
  1669.                     FI
  1670.  
  1671.                     terminated = TRUE;
  1672.                     mapgen = TRUE;
  1673.                     break;
  1674.                 case MYGAD_BUTTON3:
  1675.                     //printf("Found Presets Button.\n");
  1676.                     //alert(mywin,NULL,"Not implemented yet!","RATS!");
  1677.                     do_presets(); 
  1678.                     rast_port = mywin->RPort;
  1679.                     for (ctr = 0; ctr<=14; ctr++) {
  1680.                         SetAPen(rast_port,BLACK);
  1681.                         px_outline_hex(5+30*ctr,15);
  1682.                         if (terrain_index[ctr]<16)
  1683.                             px_plot_hex(5+30*ctr,15,terrain_index[ctr]);
  1684.                     OD
  1685.  
  1686.         }
  1687.     
  1688.     if (terminated == FALSE) {
  1689.         tot = figctr[0]+figctr[1]+figctr[2]+figctr[3]+figctr[4]+figctr[5]+
  1690.             figctr[6]+figctr[7]+figctr[8]+figctr[9]+figctr[10]+
  1691.             figctr[11]+figctr[12]+figctr[13]+figctr[14];
  1692.   
  1693.         sprintf(foo,"%ld ",tot);
  1694.         plot_text(540,85,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  1695.     FI
  1696. }
  1697.  
  1698.  
  1699. struct Gadget *createAllGadgets(struct Gadget **glistptr, void *vi,
  1700.     WORD slider_level, struct Gadget *my_gads[])
  1701. {
  1702.         struct NewGadget ng;
  1703.         struct Gadget *gad;
  1704.         
  1705.         gad = CreateContext(glistptr);
  1706.         
  1707.         ng.ng_LeftEdge  = 14;
  1708.         ng.ng_TopEdge   = 60;
  1709.         ng.ng_Width     = 15;
  1710.         ng.ng_Height    = 150;
  1711.         ng.ng_GadgetText = NULL;
  1712.         ng.ng_TextAttr  = &topaz11;
  1713.         ng.ng_VisualInfo = vi;
  1714.         ng.ng_GadgetID  = MYGAD_SLIDER;
  1715.         ng.ng_Flags     = NG_HIGHLABEL;
  1716.                             
  1717.         my_gads[MYGAD_SLIDER] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1718.             GTSL_Min,   SLIDER_MIN,
  1719.             GTSL_Max,   SLIDER_MAX,
  1720.             GTSL_Level, slider_level,
  1721.             GTSL_LevelFormat, "%21d",
  1722.             //GTSL_MaxLevelLen, 3,
  1723.             GA_RelVerify, TRUE,
  1724.             PGA_Freedom, LORIENT_VERT,
  1725.             TAG_END);
  1726.         ng.ng_LeftEdge   += 30;
  1727.         ng.ng_GadgetID   = MYGAD_SLIDER2;
  1728.         my_gads[MYGAD_SLIDER2] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1729.             GTSL_Min,   SLIDER_MIN,
  1730.             GTSL_Max,   SLIDER_MAX,
  1731.             GTSL_Level, slider_level,
  1732.             GTSL_LevelFormat, "%21d",
  1733.             //GTSL_MaxLevelLen, 3,
  1734.             GA_RelVerify, TRUE,
  1735.             PGA_Freedom, LORIENT_VERT,
  1736.             TAG_END);        
  1737.         ng.ng_LeftEdge   += 30;
  1738.         ng.ng_GadgetID   = MYGAD_SLIDER3;
  1739.         my_gads[MYGAD_SLIDER3] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1740.             GTSL_Min,   SLIDER_MIN,
  1741.             GTSL_Max,   SLIDER_MAX,
  1742.             GTSL_Level, slider_level,
  1743.             GTSL_LevelFormat, "%21d",
  1744.             //GTSL_MaxLevelLen, 3,
  1745.             GA_RelVerify, TRUE,
  1746.             PGA_Freedom, LORIENT_VERT,
  1747.             TAG_END);
  1748.         ng.ng_LeftEdge   += 30;
  1749.         ng.ng_GadgetID   = MYGAD_SLIDER4;
  1750.         my_gads[MYGAD_SLIDER4] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1751.             GTSL_Min,   SLIDER_MIN,
  1752.             GTSL_Max,   SLIDER_MAX,
  1753.             GTSL_Level, slider_level,
  1754.             GTSL_LevelFormat, "%21d",
  1755.             //GTSL_MaxLevelLen, 3,
  1756.             GA_RelVerify, TRUE,
  1757.             PGA_Freedom, LORIENT_VERT,
  1758.             TAG_END);
  1759.         ng.ng_LeftEdge   += 30;
  1760.         ng.ng_GadgetID   = MYGAD_SLIDER5;
  1761.         my_gads[MYGAD_SLIDER5] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1762.             GTSL_Min,   SLIDER_MIN,
  1763.             GTSL_Max,   SLIDER_MAX,
  1764.             GTSL_Level, slider_level,
  1765.             GTSL_LevelFormat, "%21d",
  1766.             //GTSL_MaxLevelLen, 3,
  1767.             GA_RelVerify, TRUE,
  1768.             PGA_Freedom, LORIENT_VERT,
  1769.             TAG_END);
  1770.         ng.ng_LeftEdge   += 30;
  1771.         ng.ng_GadgetID   = MYGAD_SLIDER6;
  1772.         my_gads[MYGAD_SLIDER6] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1773.             GTSL_Min,   SLIDER_MIN,
  1774.             GTSL_Max,   SLIDER_MAX,
  1775.             GTSL_Level, slider_level,
  1776.             GTSL_LevelFormat, "%21d",
  1777.             //GTSL_MaxLevelLen, 3,
  1778.             GA_RelVerify, TRUE,
  1779.             PGA_Freedom, LORIENT_VERT,
  1780.             TAG_END);
  1781.         ng.ng_LeftEdge   += 30;
  1782.         ng.ng_GadgetID   = MYGAD_SLIDER7;
  1783.         my_gads[MYGAD_SLIDER7] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1784.             GTSL_Min,   SLIDER_MIN,
  1785.             GTSL_Max,   SLIDER_MAX,
  1786.             GTSL_Level, slider_level,
  1787.             GTSL_LevelFormat, "%21d",
  1788.             //GTSL_MaxLevelLen, 3,
  1789.             GA_RelVerify, TRUE,
  1790.             PGA_Freedom, LORIENT_VERT,
  1791.             TAG_END);    
  1792.         ng.ng_LeftEdge   += 30;
  1793.         ng.ng_GadgetID   = MYGAD_SLIDER8;
  1794.         my_gads[MYGAD_SLIDER8] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1795.             GTSL_Min,   SLIDER_MIN,
  1796.             GTSL_Max,   SLIDER_MAX,
  1797.             GTSL_Level, slider_level,
  1798.             GTSL_LevelFormat, "%21d",
  1799.             //GTSL_MaxLevelLen, 3,
  1800.             GA_RelVerify, TRUE,
  1801.             PGA_Freedom, LORIENT_VERT,
  1802.             TAG_END);        
  1803.         ng.ng_LeftEdge   += 30;
  1804.         ng.ng_GadgetID   = MYGAD_SLIDER9;
  1805.         my_gads[MYGAD_SLIDER9] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1806.             GTSL_Min,   SLIDER_MIN,
  1807.             GTSL_Max,   SLIDER_MAX,
  1808.             GTSL_Level, slider_level,
  1809.             GTSL_LevelFormat, "%21d",
  1810.             //GTSL_MaxLevelLen, 3,
  1811.             GA_RelVerify, TRUE,
  1812.             PGA_Freedom, LORIENT_VERT,
  1813.             TAG_END);        
  1814.         ng.ng_LeftEdge   += 30;
  1815.         ng.ng_GadgetID   = MYGAD_SLIDER10;
  1816.         my_gads[MYGAD_SLIDER10] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1817.             GTSL_Min,   SLIDER_MIN,
  1818.             GTSL_Max,   SLIDER_MAX,
  1819.             GTSL_Level, slider_level,
  1820.             GTSL_LevelFormat, "%21d",
  1821.             //GTSL_MaxLevelLen, 3,
  1822.             GA_RelVerify, TRUE,
  1823.             PGA_Freedom, LORIENT_VERT,
  1824.             TAG_END);         
  1825.         ng.ng_LeftEdge   += 30;
  1826.         ng.ng_GadgetID   = MYGAD_SLIDER11;
  1827.         my_gads[MYGAD_SLIDER11] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1828.             GTSL_Min,   SLIDER_MIN,
  1829.             GTSL_Max,   SLIDER_MAX,
  1830.             GTSL_Level, slider_level,
  1831.             GTSL_LevelFormat, "%21d",
  1832.             //GTSL_MaxLevelLen, 3,
  1833.             GA_RelVerify, TRUE,
  1834.             PGA_Freedom, LORIENT_VERT,
  1835.             TAG_END);         
  1836.         ng.ng_LeftEdge   += 30;
  1837.         ng.ng_GadgetID   = MYGAD_SLIDER12;
  1838.         my_gads[MYGAD_SLIDER12] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1839.             GTSL_Min,   SLIDER_MIN,
  1840.             GTSL_Max,   SLIDER_MAX,
  1841.             GTSL_Level, slider_level,
  1842.             GTSL_LevelFormat, "%21d",
  1843.             //GTSL_MaxLevelLen, 3,
  1844.             GA_RelVerify, TRUE,
  1845.             PGA_Freedom, LORIENT_VERT,
  1846.             TAG_END);        
  1847.         ng.ng_LeftEdge   += 30;
  1848.         ng.ng_GadgetID   = MYGAD_SLIDER13;
  1849.         my_gads[MYGAD_SLIDER13] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1850.             GTSL_Min,   SLIDER_MIN,
  1851.             GTSL_Max,   SLIDER_MAX,
  1852.             GTSL_Level, slider_level,
  1853.             GTSL_LevelFormat, "%21d",
  1854.             //GTSL_MaxLevelLen, 3,
  1855.             GA_RelVerify, TRUE,
  1856.             PGA_Freedom, LORIENT_VERT,
  1857.             TAG_END);         
  1858.         ng.ng_LeftEdge   += 30;
  1859.         ng.ng_GadgetID   = MYGAD_SLIDER14;
  1860.         my_gads[MYGAD_SLIDER14] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1861.             GTSL_Min,   SLIDER_MIN,
  1862.             GTSL_Max,   SLIDER_MAX,
  1863.             GTSL_Level, slider_level,
  1864.             GTSL_LevelFormat, "%21d",
  1865.             //GTSL_MaxLevelLen, 3,
  1866.             GA_RelVerify, TRUE,
  1867.             PGA_Freedom, LORIENT_VERT,
  1868.             TAG_END);         
  1869.         ng.ng_LeftEdge   += 30;
  1870.         ng.ng_GadgetID   = MYGAD_SLIDER15;
  1871.         my_gads[MYGAD_SLIDER15] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1872.             GTSL_Min,   SLIDER_MIN,
  1873.             GTSL_Max,   SLIDER_MAX,
  1874.             GTSL_Level, slider_level,
  1875.             GTSL_LevelFormat, "%21d",
  1876.             //GTSL_MaxLevelLen, 3,
  1877.             GA_RelVerify, TRUE,
  1878.             PGA_Freedom, LORIENT_VERT,
  1879.             TAG_END);         
  1880.         ng.ng_LeftEdge   += 30;
  1881.         ng.ng_GadgetID   = MYGAD_SLIDER16;
  1882.         my_gads[MYGAD_SLIDER16] = gad = CreateGadget(SLIDER_KIND, gad, &ng,
  1883.             GTSL_Min,   SLIDER_MIN,
  1884.             GTSL_Max,   SLIDER_MAX,
  1885.             GTSL_Level, slider_level,
  1886.             GTSL_LevelFormat, "%21d",
  1887.             //GTSL_MaxLevelLen, 3,
  1888.             GA_RelVerify, TRUE,
  1889.             PGA_Freedom, LORIENT_VERT,
  1890.             TAG_END);  
  1891.         ng.ng_LeftEdge  = 510;
  1892.         ng.ng_TopEdge   = 160;
  1893.         ng.ng_Width     = 95;
  1894.         ng.ng_Height    = 15;
  1895.         ng.ng_GadgetText= "HELP!";
  1896.         ng.ng_GadgetID  = MYGAD_BUTTON;
  1897.         ng.ng_Flags     = 0;
  1898.         my_gads[MYGAD_BUTTON] = gad = CreateGadget(BUTTON_KIND, gad, &ng, TAG_END);
  1899.         ng.ng_TopEdge   = 190;
  1900.         ng.ng_Width     = 95;
  1901.         ng.ng_Height    = 15;
  1902.         ng.ng_GadgetText= "Generate";
  1903.         ng.ng_GadgetID  = MYGAD_BUTTON2;
  1904.         ng.ng_Flags     = 0;
  1905.         my_gads[MYGAD_BUTTON2] = gad = CreateGadget(BUTTON_KIND, gad, &ng,TAG_END);
  1906.         ng.ng_TopEdge   = 220;
  1907.         ng.ng_Width     = 95;
  1908.         ng.ng_Height    = 15;
  1909.         ng.ng_GadgetText= "Presets";
  1910.         ng.ng_GadgetID  = MYGAD_BUTTON3;
  1911.         ng.ng_Flags     = 0;
  1912.         gad = CreateGadget(BUTTON_KIND, gad, &ng,TAG_END);
  1913. return(gad);
  1914. }
  1915.  
  1916. void process_window_events(struct Window *mywin,
  1917.         WORD *slider_level, struct Gadget *my_gads[])
  1918. {        
  1919.         struct IntuiMessage *imsg;
  1920.         ULONG imsgClass;
  1921.         UWORD imsgCode;
  1922.         struct Gadget *gad;
  1923.         
  1924.                       
  1925.         while (!terminated)
  1926.         {
  1927.                 Wait (1 << mywin->UserPort->mp_SigBit);
  1928.                 while ((!terminated) &&
  1929.                     (imsg = GT_GetIMsg(mywin->UserPort)))
  1930.                 {
  1931.                         gad = (struct Gadget *)imsg->IAddress;
  1932.                         
  1933.                         imsgClass = imsg->Class;
  1934.                         imsgCode = imsg->Code;
  1935.                         
  1936.                         GT_ReplyIMsg(imsg);
  1937.                                              
  1938.                         switch (imsgClass)
  1939.                         {
  1940.                
  1941.                                 case IDCMP_CLOSEWINDOW:
  1942.                                     rast_port = mywin->RPort;
  1943.                                     terminated = TRUE;
  1944.                                     break;
  1945.                                 case IDCMP_GADGETDOWN:
  1946.                                 case IDCMP_MOUSEMOVE:
  1947.                                 case IDCMP_GADGETUP:
  1948.                                     handleGadgetEvent(mywin, gad,
  1949.                                         imsgCode, slider_level, my_gads);
  1950.                                     break;
  1951.                                 case IDCMP_REFRESHWINDOW:
  1952.                                     GT_BeginRefresh(mywin);
  1953.                                     GT_EndRefresh(mywin, TRUE);
  1954.                                     GT_RefreshWindow(mywin, NULL);
  1955.  
  1956.                                     //BeginRefresh(mywin);
  1957.                                     //EndRefresh(mywin, TRUE);
  1958.                                     break;
  1959.                                 
  1960.                         }
  1961.                }
  1962.         }
  1963. //terminated = FALSE;
  1964. }
  1965.  
  1966. void Random_Window()
  1967. {  // everything for the stats window
  1968.         struct Window   *mywin;
  1969.         struct Gadget   *glist, *my_gads[19];
  1970.         void            *vi;
  1971.         WORD            slider_level = 0;
  1972.         UWORD           topborder;
  1973.         int             ctr;
  1974.         int             tot = 0;
  1975.         static int x, y, z, ctx, cty, spot;
  1976.         static int maxx;
  1977.         static int maxy;
  1978.         struct rtHandlerInfo *handle;
  1979.         //static char *a, *b;
  1980.                 
  1981.         //int figctr[] = {
  1982.         //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  1983.         //};
  1984.                     
  1985.    //for (ctr=0; ctr<=14; ctr++) {
  1986.    //     figctr[ctr] = slider_level;
  1987.    //OD 
  1988.  
  1989.    terminated = FALSE;
  1990.    mapgen = FALSE;
  1991.     
  1992.    // make sure user doesn't play with the map window now
  1993.    SetPointer(map_window,BUSY_POINTER);
  1994.    ModifyIDCMP(map_window,NULL);
  1995.  
  1996.    // create the gadgets
  1997.         vi = GetVisualInfo(map_screen, TAG_END);
  1998.         
  1999.         topborder = map_screen->WBorTop + (map_screen->Font->ta_YSize + 1);
  2000.          
  2001.        createAllGadgets(&glist, vi, slider_level, my_gads);
  2002.             //clean_exit(1,"createAllGadgets() failed");
  2003.  
  2004.  
  2005.    // do the window itself
  2006.         mywin = OpenWindowTags(NULL,
  2007.                       WA_Gadgets, glist, WA_AutoAdjust, TRUE,
  2008.                       WA_Title,"Random Map Generator",
  2009.                       WA_Top,100,    WA_Left,7,
  2010.                       WA_Width,612,  WA_Height,250,
  2011.                       WA_SimpleRefresh, TRUE,  
  2012.                       WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS
  2013.                         |IDCMP_GADGETUP|IDCMP_REFRESHWINDOW|SLIDERIDCMP
  2014.                         |BUTTONIDCMP,
  2015.                       WA_Flags,ACTIVATE|WFLG_DRAGBAR|WFLG_SMART_REFRESH
  2016.                         |WFLG_CLOSEGADGET,
  2017.                       WA_CustomScreen,map_screen,
  2018.                       TAG_END);
  2019.  
  2020.        if (mywin==NULL)
  2021.           clean_exit(1,"ERROR: Unable to open random window!");
  2022.  
  2023.        rast_port = mywin->RPort;
  2024.  
  2025.        for (ctr = 0; ctr<=14; ctr++) {
  2026.          SetAPen(rast_port,BLACK);
  2027.          px_outline_hex(5+30*ctr,15);
  2028.          if (terrain_index[ctr]<16)
  2029.              px_plot_hex(5+30*ctr,15,terrain_index[ctr]);
  2030.        OD
  2031.      
  2032.        for (ctr=0; ctr <=14; ctr++) {
  2033.            sprintf(foo,"%ld ",slider_level);
  2034.            plot_text(10+30*ctr,220,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2035.        OD
  2036.  
  2037.  
  2038.  
  2039.        frame(510,70,80,30,TRUE);
  2040.        sprintf(foo,"TOTAL");
  2041.        plot_text(530,66,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2042.        sprintf(foo,"0 ");
  2043.        plot_text(540,85,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  2044.  
  2045.  
  2046.        GT_RefreshWindow(mywin, NULL);
  2047.                  
  2048.        process_window_events(mywin, &slider_level, my_gads);
  2049.                      
  2050.        // now clean everything up and leave
  2051.        
  2052.        rast_port = map_window->RPort;
  2053.        CloseWindow(mywin);
  2054.        mywin = NULL;
  2055.        FreeGadgets(glist);
  2056.        ClearPointer(map_window);
  2057.        ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  2058.        
  2059.        
  2060.        if (mapgen) {
  2061.            sprintf(foo,"Clearing current map and\nGenerating Random map.\nPlease wait...");
  2062.            handle = post_it(foo);      
  2063.            if (alloc_map(&me_grid)==FALSE)
  2064.                 clean_exit(2,"ERROR: Fatal RAM allocation disaster!");
  2065.            int_grid(me_grid,HEX_UNEXPLORED);
  2066.            flood_map(t_grid,HEX_OCEAN);
  2067.            ME_draw_map();
  2068.            maxx = map_window->Width-map_window->BorderRight-16;
  2069.            maxy = map_window->Height-map_window->BorderBottom-12;
  2070.            z = width * height;
  2071.            cty = 0;
  2072.                     
  2073.            for (ctx=0; ctx<=14; ctx++) {    
  2074.                 cty = 0;
  2075.                 brush = terrain_index[ctx];
  2076.                 if (figctr[ctx] == 0)
  2077.                      continue;
  2078.                 spot = z * figctr[ctx] / 100;
  2079.                 //sprintf(foo,"%ld",spot);
  2080.                 //alert(map_window,NULL,foo,"Okay");
  2081.                 while (cty<spot) {        
  2082.                      x = RangeRand(width);
  2083.                      y = RangeRand(height); 
  2084.                      
  2085.                      
  2086.                      while (x>=width || y>=height) {
  2087.                         x-=1;
  2088.                         y-=1;
  2089.                      OD
  2090.                      
  2091.                      while (get(me_grid,x,y)!=HEX_UNEXPLORED) {
  2092.                          x-=1;
  2093.                          y-=1;
  2094.                          if (x<=0 || y<=0) {
  2095.                              x = RangeRand(width);
  2096.                              y = RangeRand(height);
  2097.                              if (x>=width || y>=height) {
  2098.                                 x = RangeRand(width);
  2099.                                 y = RangeRand(height);
  2100.                              FI
  2101.                          FI
  2102.                      OD
  2103.                      
  2104.                      map_safe = FALSE;
  2105.  
  2106.                      // plot in and adjacent to a given hex
  2107.                      if(get(me_grid,x,y) == HEX_UNEXPLORED) {
  2108.                         //sprintf(bar,"*........");
  2109.                         //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2110.                         put(t_grid,x,y,terrain_index[ctx]);
  2111.                         put(me_grid,x,y,terrain_index[ctx]);
  2112.                         cty++;
  2113.                         if (visibleP(x,y))
  2114.                             plot_hex(x,y,terrain_index[ctx]);
  2115.                      FI
  2116.                      if(x-1<=0)
  2117.                         continue;
  2118.                      if((cty<spot) && get(me_grid,x-1,y) == HEX_UNEXPLORED) {       
  2119.                         //sprintf(bar,".*.......");
  2120.                         //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2121.                         put(t_grid,x-1,y,terrain_index[ctx]);
  2122.                         put(me_grid,x-1,y,terrain_index[ctx]);
  2123.                         cty++;
  2124.                         if (visibleP(x-1,y))
  2125.                             plot_hex(x-1,y,terrain_index[ctx]);
  2126.                      FI
  2127.                      if(x+1>=width)
  2128.                         continue;
  2129.                      if((cty<spot) && get(me_grid,x+1,y) == HEX_UNEXPLORED) {
  2130.                         //sprintf(bar,"..*......");
  2131.                         //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2132.                         put(t_grid,x+1,y,terrain_index[ctx]);
  2133.                         put(me_grid,x+1,y,terrain_index[ctx]);
  2134.                         cty++;
  2135.                         if (visibleP(x+1,y))
  2136.                             plot_hex(x+1,y,terrain_index[ctx]);
  2137.                      FI
  2138.                      if(y-1<=0)
  2139.                         continue;
  2140.                      if((cty<spot) && get(me_grid,x,y-1) == HEX_UNEXPLORED) {
  2141.                         //sprintf(bar,"...*.....");
  2142.                         //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2143.                         put(t_grid,x,y-1,terrain_index[ctx]);
  2144.                         put(me_grid,x,y-1,terrain_index[ctx]);
  2145.                         cty++;
  2146.                         if (visibleP(x,y-1))
  2147.                             plot_hex(x,y-1,terrain_index[ctx]);
  2148.                      FI
  2149.                      if(y+1>=height)
  2150.                         continue;
  2151.                      if((cty<spot) && get(me_grid,x,y+1) == HEX_UNEXPLORED) {
  2152.                         //sprintf(bar,"....*....");
  2153.                         //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2154.                         put(t_grid,x,y+1,terrain_index[ctx]);
  2155.                         put(me_grid,x,y+1,terrain_index[ctx]);
  2156.                         cty++;
  2157.                         if (visibleP(x,y+1))
  2158.                             plot_hex(x,y+1,terrain_index[ctx]);
  2159.                      FI
  2160.                      if (y%2) {  /* i.e. if it's an odd-numbered column */
  2161.                         if(x+1>=width || y-1<=0)
  2162.                             continue;
  2163.                         if((cty<spot) && get(me_grid,x+1,y-1) == HEX_UNEXPLORED) {
  2164.                             //sprintf(bar,".....*...");
  2165.                             //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2166.                             put(t_grid,x+1,y-1,terrain_index[ctx]);
  2167.                             put(me_grid,x+1,y-1,terrain_index[ctx]);
  2168.                             cty++;
  2169.                             if (visibleP(x+1,y-1))
  2170.                                 plot_hex(x+1,y-1,terrain_index[ctx]);
  2171.                         FI
  2172.                         if(x+1>=width || y+1>=height)
  2173.                             continue;
  2174.                         if((cty<spot) && get(me_grid,x+1,y+1) == HEX_UNEXPLORED) {
  2175.                             //sprintf(bar,"......*..");
  2176.                             //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2177.                             put(t_grid,x+1,y+1,terrain_index[ctx]);
  2178.                             put(me_grid,x+1,y+1,terrain_index[ctx]);
  2179.                             cty++;
  2180.                             if (visibleP(x+1,y+1))
  2181.                                 plot_hex(x+1,y+1,terrain_index[ctx]);
  2182.                         FI
  2183.                      } else {
  2184.                         if(x-1<=0 || y-1<=0)
  2185.                             continue;
  2186.                         if((cty<spot) && get(me_grid,x-1,y-1) == HEX_UNEXPLORED) {
  2187.                             //sprintf(bar,".......*.");
  2188.                             //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2189.                             put(t_grid,x-1,y-1,terrain_index[ctx]);
  2190.                             put(me_grid,x-1,y-1,terrain_index[ctx]);
  2191.                             cty++;
  2192.                             if (visibleP(x-1,y-1))
  2193.                                 plot_hex(x-1,y-1,terrain_index[ctx]);
  2194.                         FI
  2195.                         if(x-1<=0 || y+1>=height)
  2196.                             continue;
  2197.                         if((cty<spot) && get(me_grid,x-1,y+1) == HEX_UNEXPLORED) {
  2198.                             //sprintf(bar,"........*");
  2199.                             //plot_text(540,20,bar,LT_BLUE,BLACK,JAM2,&topaz11);
  2200.                             put(t_grid,x-1,y+1,terrain_index[ctx]);
  2201.                             put(me_grid,x-1,y+1,terrain_index[ctx]);
  2202.                             cty++;
  2203.                             if (visibleP(x-1,y+1))
  2204.                                 plot_hex(x-1,y+1,terrain_index[ctx]);
  2205.                         FI
  2206.                      FI
  2207.                     
  2208.                      
  2209.                      
  2210.                           
  2211.                 OD
  2212.                         
  2213.                 //tot_hex -= figctr[ctx];
  2214.                 //figctr[ctx] -= 1;
  2215.            OD                           
  2216.                         
  2217.                 
  2218.              
  2219.              
  2220.              brush = HEX_PLAINS;
  2221.              {  // set the MX menu items to reflect this change
  2222.                 struct MenuItem *item;
  2223.                 int ctr;
  2224.  
  2225.                 item = ItemAddress(editor_menu_strip,FULLMENUNUM(1,2,0));
  2226.                 for (ctr = 1; ctr<=16; ctr++) {
  2227.                    if (ctr==brush)
  2228.                        item->Flags |= CHECKED;
  2229.                    else
  2230.                        item->Flags &= ~CHECKED;
  2231.                    item = item->NextItem;
  2232.                 OD
  2233.              }
  2234.  
  2235.                 
  2236.              for (ctr=0; ctr<=14; ctr++) {
  2237.                 figctr[ctr] = 0;
  2238.                    
  2239.              OD
  2240.              
  2241.                           
  2242.              tot=0;
  2243.              alert(map_window,NULL,"Map Generated!","Okay");
  2244.              do_city(); 
  2245.              unpost_it(handle);
  2246.        FI
  2247.        mapgen = FALSE;
  2248. }
  2249.  
  2250. void do_presets()
  2251. {
  2252.    struct Window *presets_window = NULL;
  2253.    struct Gadget *context, *map_slide, *ok_gad, *help_gad, *cancel_gad;
  2254.    struct Gadget *s1_gad, *s2_gad, *s3_gad;
  2255.    struct NewGadget generic = {
  2256.       6,30,      // leftedge, topedge
  2257.       57,15,   // width, height
  2258.       "Okay",  // text label
  2259.       &topaz11bold,    // font
  2260.       3,       // gadget ID
  2261.       NULL,NULL,NULL
  2262.    };
  2263.    struct NewGadget slider = {
  2264.       40,20,
  2265.       125,13,
  2266.       NULL,
  2267.       &topaz11,
  2268.       5,
  2269.       NULL,
  2270.       NULL, NULL
  2271.    };
  2272.    
  2273.     
  2274.    // make sure user doesn't play with the map window now
  2275.    SetPointer(map_window,BUSY_POINTER);
  2276.    ModifyIDCMP(map_window,NULL);
  2277.  
  2278.    // create the gadgets
  2279.    if (!CreateContext(&context))
  2280.       clean_exit(1,"Unable to create context gadget!");
  2281.    slider.ng_VisualInfo = vi;
  2282.    map_slide = CreateGadget(SLIDER_KIND,context,&slider,
  2283.       GTSL_Min, 0,
  2284.       GTSL_Max, 100,
  2285.       GTSL_Level, 0,
  2286.       GA_RelVerify, TRUE,
  2287.       TAG_END);
  2288.    generic.ng_VisualInfo = vi;
  2289.    generic.ng_TextAttr = &topaz11;
  2290.    generic.ng_TopEdge += 17;
  2291.    generic.ng_GadgetText = "Desert";
  2292.    s1_gad = CreateGadget(BUTTON_KIND,map_slide,&generic,TAG_END);
  2293.    generic.ng_TopEdge += 17;
  2294.    generic.ng_GadgetText = "Jungle";
  2295.    s2_gad = CreateGadget(BUTTON_KIND,s1_gad,&generic,TAG_END);
  2296.    generic.ng_TopEdge += 17;
  2297.    generic.ng_GadgetText = "Water";
  2298.    s3_gad = CreateGadget(BUTTON_KIND,s2_gad,&generic,TAG_END);
  2299.    generic.ng_TopEdge += 17;
  2300.    generic.ng_TextAttr = &topaz11bold;
  2301.    generic.ng_GadgetText = "OK";
  2302.    ok_gad = CreateGadget(BUTTON_KIND,s3_gad,&generic,TAG_END);
  2303.    generic.ng_LeftEdge += 66;
  2304.    generic.ng_TextAttr = &topaz11;
  2305.    generic.ng_GadgetText = "HELP!";
  2306.    help_gad = CreateGadget(BUTTON_KIND,ok_gad,&generic,TAG_END);
  2307.    generic.ng_LeftEdge += 66;
  2308.    generic.ng_GadgetText = "Cancel";
  2309.    cancel_gad = CreateGadget(BUTTON_KIND,help_gad,&generic,TAG_END);
  2310.  
  2311.    // do the window itself
  2312.    presets_window = OpenWindowTags(NULL,
  2313.       WA_Gadgets,context,
  2314.       WA_Title,"Map Presets Creator",
  2315.       WA_Top,100,    WA_Left,200,
  2316.       WA_Width,212,  WA_Height,125,
  2317.       WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_MOUSEBUTTONS|IDCMP_GADGETUP,
  2318.       WA_Flags,NOCAREREFRESH|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_CLOSEGADGET,
  2319.       WA_CustomScreen,map_screen,
  2320.       TAG_END );
  2321.    if (presets_window==NULL)
  2322.       clean_exit(1,"ERROR: Unable to open presets window!");
  2323.    rast_port = presets_window->RPort;
  2324.  
  2325.    sprintf(foo,"0");
  2326.    plot_text(5+95,50,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2327.    
  2328.    {  // handle the user actions here
  2329.       struct IntuiMessage *message; // the message the IDCMP sends us
  2330.       //struct MenuItem *item;
  2331.       //int ctr;
  2332.             
  2333.       // useful for interpreting IDCMP messages
  2334.       UWORD code;
  2335.       ULONG class;
  2336.       APTR object;
  2337.  
  2338.       while (TRUE) {
  2339.          WaitPort(presets_window->UserPort);
  2340.          while (message = GT_GetIMsg(presets_window->UserPort)) {
  2341.             code = message->Code;  
  2342.             object = message->IAddress;  
  2343.             class = message->Class;
  2344.             GT_ReplyIMsg(message);
  2345.             //if (class==MOUSEBUTTONS && code==SELECTDOWN)
  2346.             //   new_terrain(message->MouseX,message->MouseY);
  2347.             if (class==IDCMP_VANILLAKEY && code==13) {
  2348.                 mycity = TRUE;
  2349.                 goto exit_presets_window;
  2350.             FI
  2351.             if (class==GADGETUP) {
  2352.                if (object==map_slide) {
  2353.                  GT_SetGadgetAttrs(NULL, presets_window,NULL,
  2354.                     GTIN_Number, code,
  2355.                     TAG_END);
  2356.                  tot = code;
  2357.                  sprintf(foo,"%ld ",tot);
  2358.                  plot_text(5+95,50,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2359.                  if (tot >= 1)
  2360.                     mycity = TRUE; 
  2361.                FI   
  2362.                if (object==s1_gad) 
  2363.                   alert(presets_window,NULL,"Not implemented yet!","RATS!"); 
  2364.                if (object==s2_gad)
  2365.                   alert(presets_window,NULL,"Not implemented yet!","RATS!");
  2366.                if (object==s3_gad)
  2367.                   alert(presets_window,NULL,"Not implemented yet!","RATS!");
  2368.                if (object==ok_gad) {
  2369.                   mycity = TRUE;
  2370.                   goto exit_presets_window;
  2371.                FI             
  2372.                if (object==help_gad) {
  2373.                   sprintf(foo,"Slider selects terrain amount.\n\n");
  2374.                   strcat(foo,"Ok button will create Preset.\n\n");
  2375.                   strcat(foo,"Cancel button will cancel this option.");
  2376.                   alert(presets_window,NULL,foo,"Okay");
  2377.                FI       
  2378.                if (object==cancel_gad) {
  2379.                   mycity = FALSE;
  2380.                   goto exit_presets_window;
  2381.                FI 
  2382.             FI
  2383.             if (class==CLOSEWINDOW) {
  2384.                mycity = FALSE;
  2385.                goto exit_presets_window;
  2386.             FI
  2387.          OD
  2388.       OD
  2389.    }
  2390.    exit_presets_window:
  2391.  
  2392.  
  2393.    // now clean everything up and leave
  2394.        rast_port = map_window->RPort;
  2395.        CloseWindow(presets_window);
  2396.        presets_window = NULL;
  2397.        FreeGadgets(context);
  2398.        ClearPointer(map_window);
  2399.        ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  2400.    
  2401. }
  2402.  
  2403. void do_city()
  2404. {
  2405.    struct Window *mycity_window = NULL;
  2406.    struct Gadget *context, *city_string, *cityport_string, *plus_gad, *minus_gad, *plusport_gad, *minusport_gad, *ok_gad, *help_gad, *cancel_gad;
  2407.    struct NewGadget generic = {
  2408.       6,100,      // leftedge, topedge
  2409.       15,15,   // width, height
  2410.       "Okay",  // text label
  2411.       &topaz11bold,    // font
  2412.       3,       // gadget ID
  2413.       NULL,NULL,NULL
  2414.    };
  2415.    struct NewGadget stringfield = {
  2416.       40,20,
  2417.       125,16,
  2418.       NULL,
  2419.       &topaz11,
  2420.       2,
  2421.       PLACETEXT_LEFT,
  2422.       NULL,NULL
  2423.    };
  2424.    static int x, y, zot;
  2425.    static int maxx, maxy;
  2426.    
  2427.    tot = 0;
  2428.    totP = 0;
  2429.     
  2430.    // make sure user doesn't play with the map window now
  2431.    SetPointer(map_window,BUSY_POINTER);
  2432.    ModifyIDCMP(map_window,NULL);
  2433.  
  2434.    // create the gadgets
  2435.    if (!CreateContext(&context))
  2436.       clean_exit(1,"Unable to create context gadget!");
  2437.    stringfield.ng_VisualInfo = vi;
  2438.    strcpy(foo,"0");
  2439.    city_string = CreateGadget(STRING_KIND,context,&stringfield,
  2440.       GTST_String, foo,
  2441.       GTST_MaxChars, 128L,
  2442.       STRINGA_Justification, GACT_STRINGCENTER,
  2443.       TAG_END);
  2444.    stringfield.ng_TopEdge +=40;
  2445.    strcpy(foo,"0");
  2446.    cityport_string = CreateGadget(STRING_KIND,city_string,&stringfield,
  2447.       GTST_String, foo,
  2448.       GTST_MaxChars, 128L,
  2449.       STRINGA_Justification, GACT_STRINGCENTER,
  2450.       TAG_END);
  2451.    generic.ng_VisualInfo = vi;
  2452.    generic.ng_TextAttr = &topaz11;
  2453.    generic.ng_LeftEdge = 24;
  2454.    generic.ng_TopEdge = 20;
  2455.    generic.ng_GadgetText = "-";
  2456.    minus_gad = CreateGadget(BUTTON_KIND,cityport_string,&generic,TAG_END);
  2457.    generic.ng_LeftEdge = 165;
  2458.    generic.ng_TopEdge = 20;
  2459.    generic.ng_GadgetText = "+";
  2460.    plus_gad = CreateGadget(BUTTON_KIND,minus_gad,&generic,TAG_END);
  2461.    generic.ng_LeftEdge = 24;
  2462.    generic.ng_TopEdge += 40;
  2463.    generic.ng_GadgetText = "-";
  2464.    minusport_gad = CreateGadget(BUTTON_KIND,plus_gad,&generic,TAG_END);
  2465.    generic.ng_LeftEdge = 165;
  2466.    generic.ng_GadgetText = "+";
  2467.    plusport_gad = CreateGadget(BUTTON_KIND,minusport_gad,&generic,TAG_END);
  2468.    generic.ng_LeftEdge = 11;
  2469.    generic.ng_TopEdge = 100;
  2470.    generic.ng_Width = 57;
  2471.    generic.ng_GadgetText = "OK";
  2472.    ok_gad = CreateGadget(BUTTON_KIND,plusport_gad,&generic,TAG_END);
  2473.    generic.ng_LeftEdge += 66;
  2474.    generic.ng_GadgetText = "HELP!";
  2475.    help_gad = CreateGadget(BUTTON_KIND,ok_gad,&generic,TAG_END);
  2476.    generic.ng_LeftEdge += 66;
  2477.    generic.ng_GadgetText = "Cancel";
  2478.    cancel_gad = CreateGadget(BUTTON_KIND,help_gad,&generic,TAG_END);
  2479.  
  2480.    // do the window itself
  2481.    mycity_window = OpenWindowTags(NULL,
  2482.       WA_Gadgets,context,
  2483.       WA_Title,"Sprinkle Cities",
  2484.       WA_Top,100,    WA_Left,200,
  2485.       WA_Width,212,  WA_Height,125,
  2486.       WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_MOUSEBUTTONS|IDCMP_GADGETUP,
  2487.       WA_Flags,NOCAREREFRESH|WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_CLOSEGADGET,
  2488.       WA_CustomScreen,map_screen,
  2489.       TAG_END );
  2490.    if (mycity_window==NULL)
  2491.       clean_exit(1,"ERROR: Unable to open city window!");
  2492.    rast_port = mycity_window->RPort;
  2493.  
  2494.    //sprintf(foo,"0");
  2495.    //plot_text(5+95,50,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2496.    sprintf(foo,"Number of LAND Cities");
  2497.    plot_text(5+15,40,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  2498.    sprintf(foo,"Number of PORT Cities");
  2499.    plot_text(5+15,80,foo,BLUE,LT_GRAY,JAM2,&topaz11);
  2500.    
  2501.    {  // handle the user actions here
  2502.       struct IntuiMessage *message; // the message the IDCMP sends us
  2503.       //struct MenuItem *item;
  2504.       //int ctr;
  2505.             
  2506.       // useful for interpreting IDCMP messages
  2507.       UWORD code;
  2508.       ULONG class;
  2509.       APTR object;
  2510.  
  2511.       while (TRUE) {
  2512.          WaitPort(mycity_window->UserPort);
  2513.          while (message = GT_GetIMsg(mycity_window->UserPort)) {
  2514.             code = message->Code;  
  2515.             object = message->IAddress;  
  2516.             class = message->Class;
  2517.             GT_ReplyIMsg(message);
  2518.             //if (class==MOUSEBUTTONS && code==SELECTDOWN)
  2519.             //   new_terrain(message->MouseX,message->MouseY);
  2520.             if (class==IDCMP_VANILLAKEY && code==13) {
  2521.                 mycity = TRUE;
  2522.                 goto exit_mycity_window;
  2523.             FI
  2524.             if (class==GADGETUP) {
  2525.                if (object==city_string) {
  2526.                //  GT_SetGadgetAttrs(city_string, mycity_window,NULL,
  2527.                //     GTST_String, code,
  2528.                //     TAG_END);
  2529.                  tot = atoi(((struct StringInfo *)city_string->SpecialInfo)->Buffer);
  2530.                //  tot = atoi(foo);
  2531.                //  sprintf(foo,"%ld ",tot);
  2532.                //  plot_text(5+95,50,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2533.                  if (tot >= 1)
  2534.                     mycity = TRUE; 
  2535.                FI   
  2536.                if (object==cityport_string) {
  2537.                //  GT_SetGadgetAttrs(cityport_string, mycity_window,NULL,
  2538.                //     GTST_String, code,
  2539.                //     TAG_END);
  2540.                  totP = atoi(((struct StringInfo *)cityport_string->SpecialInfo)->Buffer);
  2541.                //  totP = atoi(foo);
  2542.                //  sprintf(foo,"%ld ",totP);
  2543.                //  plot_text(5+95,50,foo,BLACK,LT_GRAY,JAM2,&topaz11);
  2544.                  if (totP >= 1)
  2545.                     mycity = TRUE; 
  2546.                FI   
  2547.                if (object==minus_gad) {
  2548.                   tot -= 1;
  2549.                   if (tot < 0)
  2550.                         tot = 0;
  2551.                   sprintf(foo,"%ld",tot);
  2552.                   GT_SetGadgetAttrs(city_string,mycity_window,NULL,
  2553.                         GTST_String, foo,
  2554.                         TAG_DONE);
  2555.                FI
  2556.                if (object==plus_gad) {
  2557.                   tot += 1;
  2558.                   if (tot < 0)
  2559.                         tot = 0;
  2560.                   sprintf(foo,"%ld",tot);
  2561.                   GT_SetGadgetAttrs(city_string,mycity_window,NULL,
  2562.                         GTST_String, foo,
  2563.                         TAG_DONE);
  2564.                   mycity = TRUE;
  2565.                FI
  2566.                if (object==minusport_gad) {
  2567.                   totP -= 1;
  2568.                   if (totP < 0)
  2569.                         totP = 0;
  2570.                   sprintf(foo,"%ld",totP);
  2571.                   GT_SetGadgetAttrs(cityport_string,mycity_window,NULL,
  2572.                         GTST_String, foo,
  2573.                         TAG_DONE);
  2574.                FI
  2575.                if (object==plusport_gad) {
  2576.                   totP += 1;
  2577.                   if (totP < 0)
  2578.                         totP = 0;
  2579.                   sprintf(foo,"%ld",totP);
  2580.                   GT_SetGadgetAttrs(cityport_string,mycity_window,NULL,
  2581.                         GTST_String, foo,
  2582.                         TAG_DONE);
  2583.                   mycity = TRUE;
  2584.                FI
  2585.                if (object==ok_gad) {
  2586.                   mycity = TRUE;
  2587.                   goto exit_mycity_window;
  2588.                FI             
  2589.                if (object==help_gad) {
  2590.                   sprintf(foo,"Slider selects number \nof cities to sprinkle.\n\n");
  2591.                   strcat(foo,"Ok button will sprinkle cities.\n\n");
  2592.                   strcat(foo,"Cancel button will cancel this option.");
  2593.                   alert(mycity_window,NULL,foo,"Okay");
  2594.                FI       
  2595.                if (object==cancel_gad) {
  2596.                   mycity = FALSE;
  2597.                   goto exit_mycity_window;
  2598.                FI 
  2599.             FI
  2600.             if (class==CLOSEWINDOW) {
  2601.                mycity = FALSE;
  2602.                goto exit_mycity_window;
  2603.             FI
  2604.          OD
  2605.       OD
  2606.    }
  2607.    exit_mycity_window:
  2608.  
  2609.  
  2610.    // now clean everything up and leave
  2611.        rast_port = map_window->RPort;
  2612.        CloseWindow(mycity_window);
  2613.        mycity_window = NULL;
  2614.        FreeGadgets(context);
  2615.        ClearPointer(map_window);
  2616.        ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  2617.    
  2618.    if(mycity) {
  2619.        int num_hexes = 0;
  2620.        int ctr=0;
  2621.       
  2622.        
  2623.        maxx = map_window->Width-map_window->BorderRight-16;
  2624.        maxy = map_window->Height-map_window->BorderBottom-12;
  2625.    
  2626.        for (zot=0; zot<tot; zot++) {
  2627.          Top:
  2628.            x = RangeRand(width);
  2629.            y = RangeRand(height);
  2630.              
  2631.            //while (x>=width || y>=height) {
  2632.            //    x = RangeRand(width);
  2633.            //    y = RangeRand(height);
  2634.            //OD
  2635.            
  2636.            while (get(t_grid,x,y) >= HEX_PEAKS && get(t_grid,x,y) <= HEX_CITY) {
  2637.                x = RangeRand(width);
  2638.                y = RangeRand(height);
  2639.            OD  
  2640.            num_hexes = adjacent(x,y);
  2641.            for (; ctr<num_hexes; ctr++)
  2642.                 switch (get(t_grid,hexlist[ctr].col,hexlist[ctr].row)) {
  2643.                         case HEX_PLAINS:
  2644.                         case HEX_DESERT:
  2645.                         case HEX_BRUSH:
  2646.                         case HEX_FOREST:
  2647.                         case HEX_JUNGLE:
  2648.                         case HEX_RUGGED:
  2649.                         case HEX_HILLS:
  2650.                         case HEX_MOUNTAINS:
  2651.                                 goto Build_me;
  2652.                 OD
  2653.               
  2654.            Build_me:                                                              
  2655.                 create_city(x,y);
  2656.                 plot_city(x,y,WHITE,FALSE);
  2657.                 map_safe = FALSE;
  2658.                 if (!city_hereP(x,y)) 
  2659.                       goto Top;
  2660.        OD 
  2661.                                                                                 
  2662.        for (zot=0; zot<totP; zot++) {
  2663.          Top2:
  2664.            x = RangeRand(width);
  2665.            y = RangeRand(height);
  2666.              
  2667.            //while (x>=width || y>=height) {
  2668.            //    x = RangeRand(width);
  2669.            //    y = RangeRand(height);
  2670.            //OD
  2671.            
  2672.            while (get(t_grid,x,y) >= HEX_PEAKS && get(t_grid,x,y) <= HEX_CITY) {
  2673.                x = RangeRand(width);
  2674.                y = RangeRand(height);
  2675.            OD  
  2676.            num_hexes = adjacent(x,y);
  2677.            for (; ctr<num_hexes; ctr++)
  2678.                 switch (get(t_grid,hexlist[ctr].col,hexlist[ctr].row)) {
  2679.                         case HEX_SHALLOWS:
  2680.                         case HEX_OCEAN:
  2681.                         case HEX_DEPTH:
  2682.                                 goto Build_me2;
  2683.                 OD
  2684.               
  2685.            Build_me2:                                                              
  2686.                 create_city(x,y);
  2687.                 plot_city(x,y,WHITE,FALSE);
  2688.                 map_safe = FALSE;
  2689.                 if (!city_hereP(x,y)) 
  2690.                       goto Top2;
  2691.        OD 
  2692.         
  2693.    mycity = FALSE;     
  2694.    tot = 0;
  2695.    totP = 0;
  2696.    alert(map_window,NULL,"Cities Sprinkled!","Okay");
  2697.    FI 
  2698. }
  2699.  
  2700.  
  2701.  
  2702. void menu_select_terrain()
  2703. {  // handle terrain selection directly from the MX menu items
  2704.    struct MenuItem *item;
  2705.    int ctr;
  2706.  
  2707.    item = ItemAddress(editor_menu_strip,FULLMENUNUM(1,2,0));
  2708.    for (ctr = 1; ctr<=17; ctr++) {
  2709.       if ((item->Flags & CHECKED)!=NULL)
  2710.          brush = ctr;
  2711.       item = item->NextItem;
  2712.    OD
  2713. }
  2714.  
  2715. // end of the terrain selection area
  2716.  
  2717. void build_editor_menu()
  2718. {
  2719.    struct NewMenu new_menu_strip[]  = {
  2720.       { NM_TITLE, "Project", NULL, 0, NULL, NULL },
  2721.       { NM_ITEM, "Load Map...", "L", ITEMTEXT, NULL, NULL },
  2722.       { NM_ITEM, "Save Map...", "S", ITEMTEXT, NULL, NULL },
  2723.       { NM_ITEM, "Resize Map...", "R", ITEMTEXT, NULL, NULL },
  2724.       { NM_ITEM, "Clear Map", "C", ITEMTEXT, NULL, NULL },
  2725.       { NM_ITEM, "Exit Map Editor", "X", ITEMTEXT, NULL, NULL },
  2726.       { NM_ITEM, "Quit Program", "Q", ITEMTEXT, NULL, NULL },
  2727.       { NM_TITLE, "Terrain", NULL, 0, NULL, NULL },
  2728.       { NM_ITEM, "Toolbar   [SPC]", NULL, ITEMTEXT, NULL, NULL },
  2729.       { NM_ITEM, NM_BARLABEL, NULL, ITEMTEXT, NULL, NULL },
  2730.       { NM_ITEM, "PLAINS", NULL, CHECKIT|MENUTOGGLE|CHECKED,~4, NULL },
  2731.       { NM_ITEM, "DESERT", NULL, CHECKIT|MENUTOGGLE,~8, NULL },
  2732.       { NM_ITEM, "FORBID", NULL, CHECKIT|MENUTOGGLE,~16, NULL },
  2733.       { NM_ITEM, "BRUSH", NULL, CHECKIT|MENUTOGGLE,~32, NULL },
  2734.       { NM_ITEM, "FOREST", NULL, CHECKIT|MENUTOGGLE,~64, NULL },
  2735.       { NM_ITEM, "JUNGLE", NULL, CHECKIT|MENUTOGGLE,~128, NULL },
  2736.       { NM_ITEM, "RUGGED", NULL, CHECKIT|MENUTOGGLE,~256, NULL },
  2737.       { NM_ITEM, "HILLS", NULL, CHECKIT|MENUTOGGLE,~512, NULL },
  2738.       { NM_ITEM, "MOUNTAINS", NULL, CHECKIT|MENUTOGGLE,~1024, NULL },
  2739.       { NM_ITEM, "PEAKS", NULL, CHECKIT|MENUTOGGLE,~2048, NULL },
  2740.       { NM_ITEM, "SWAMP", NULL, CHECKIT|MENUTOGGLE,~4096, NULL },
  2741.       { NM_ITEM, "SHALLOWS", NULL, CHECKIT|MENUTOGGLE,~8192, NULL },
  2742.       { NM_ITEM, "OCEAN", NULL, CHECKIT|MENUTOGGLE,~16384, NULL },
  2743.       { NM_ITEM, "DEPTHS", NULL, CHECKIT|MENUTOGGLE,~32768, NULL },
  2744.       { NM_ITEM, "ICE", NULL, CHECKIT|MENUTOGGLE,~65536, NULL },
  2745.       { NM_ITEM, "CITY", NULL, CHECKIT|MENUTOGGLE,~131072, NULL },
  2746.       { NM_ITEM, "ROAD", NULL, CHECKIT|MENUTOGGLE,~262144, NULL },
  2747.       { NM_ITEM, NM_BARLABEL, NULL, ITEMTEXT, NULL, NULL },
  2748.       { NM_ITEM, "Info         I ", NULL, ITEMTEXT, NULL, NULL },
  2749.       { NM_TITLE, "Other", NULL, 0, NULL, NULL },
  2750.       { NM_ITEM, "World View     ", NULL, ITEMTEXT, NULL, NULL },
  2751.       { NM_ITEM, "Random Map     ", "M", ITEMTEXT, NULL, NULL },
  2752.       { NM_ITEM, "Statistics     ", "I", ITEMTEXT, NULL, NULL },
  2753.       { NM_ITEM, "Sprinkle Cities", "K", ITEMTEXT, NULL, NULL },
  2754.       { NM_ITEM, "Connect Cities ", "T", ITEMTEXT, NULL, NULL },
  2755.       { NM_END, NULL, NULL, NULL, NULL, NULL }
  2756.    };
  2757.  
  2758.    if (!(editor_menu_strip = CreateMenus(new_menu_strip,GTMN_FrontPen,BLACK,TAG_END)))
  2759.       clean_exit(1,"ERROR: Unable to create map editor menu strip!");
  2760.  
  2761.    if (!(LayoutMenus(editor_menu_strip,vi,TAG_END)))
  2762.       clean_exit(1,"ERROR: Unable to layout map editor menus!");
  2763. }
  2764.  
  2765. BOOL user_plopcity(col,row)
  2766. int col, row;
  2767. {  // look out map, here come city!
  2768.    int locale = get(t_grid,col,row);
  2769.    struct City *metro;
  2770.  
  2771.    switch (locale) {
  2772.       case HEX_FORBID:  
  2773.       case HEX_PEAKS:
  2774.       case HEX_SWAMP:
  2775.       case HEX_SHALLOWS:
  2776.       case HEX_OCEAN:
  2777.       case HEX_DEPTH:
  2778.       case HEX_ICE:
  2779.          playSound(DONK_SOUND,64);
  2780.          (void)rtEZRequestTags("You cannot build a city on that terrain.",
  2781.             "Cancel",NULL,NULL,
  2782.             RT_Window,        map_window,
  2783.             RT_ReqPos,        REQPOS_CENTERSCR,
  2784.             RT_LockWindow,    TRUE,
  2785.             RTEZ_Flags,       EZREQF_CENTERTEXT,
  2786.             TAG_DONE );
  2787.          return FALSE;
  2788.       default:
  2789.          if (metro = city_hereP(col,row)) {
  2790.             ULONG result;
  2791.             char buffer[20];
  2792.  
  2793.             outline_hex(col,row,WHITE);
  2794.             sprintf(foo,"Row: %ld  Column: %ld",metro->row,metro->col);
  2795.             (void)strcpy(buffer,metro->name);
  2796.             result = rtGetString(buffer,19,"City Information",NULL,
  2797.                RTGS_TextFmt, foo,
  2798.                RT_DEFAULT, TAG_END);
  2799.             if (result) {
  2800.                (void)strcpy(metro->name,buffer);
  2801.                map_safe = FALSE;
  2802.             FI
  2803.             outline_hex(col,row,BLACK);
  2804.             return FALSE;
  2805.          } else {
  2806.             create_city(col,row);
  2807.             plot_city(col,row,WHITE,FALSE);
  2808.             map_safe = FALSE;
  2809.             return TRUE;
  2810.          FI
  2811.    }
  2812. }
  2813.  
  2814. void user_plot(x,y,qual)
  2815. int x,y;
  2816. UWORD qual;
  2817. {  // the user plots a terrain hex with his mouse
  2818.    int col, row;
  2819.    int maxx = map_window->Width-map_window->BorderRight-16;
  2820.    int maxy = map_window->Height-map_window->BorderBottom-12;
  2821.    int lbrush = brush;  // local brush for this function only
  2822.  
  2823.    if (x>=maxx || y>=maxy)
  2824.       return;
  2825.    /*
  2826.       The behavior of this function will vary depening on whether the current
  2827.       brush is a city.  Then the editor is in "city mode" as opposed to "terrain"
  2828.       mode.  In city mode the cursor can create cities (or with SHIFT delete them),
  2829.       while leaving terrain undisturbed.  But when in terrain mode the cursor can
  2830.       draw the current terrain (or with SHIFT draw ocean) while not molesting the
  2831.       cities.
  2832.    */
  2833.    abs_to_log(x,y,&col,&row);
  2834.    if (!visibleP(col,row))
  2835.       return;
  2836.  
  2837.    /*
  2838.       This is quick-hack code for creating roads, just so I can see how they
  2839.       look, graphically.  The user is holding down CONTROL, so it pops a road
  2840.       flag into the specified hex.
  2841.    */
  2842.  
  2843.    //if (qual & IEQUALIFIER_CONTROL) {
  2844.    if (lbrush==HEX_ROADS) {
  2845.       int flag = get_flags(t_grid,col,row);
  2846.       struct City *metro=city_hereP(col,row);
  2847.  
  2848.       if (flag) {
  2849.          flag = flag & (~ROAD);  // remove road from this hex
  2850.          put_flags(t_grid,col,row,flag);
  2851.          plot_hex(col,row,get(t_grid,col,row));
  2852.          if (metro) {
  2853.             plot_city(col,row,0,FALSE);
  2854.             Remove((APTR)metro);
  2855.             AddTail((APTR)&city_list,(APTR)metro);
  2856.          }
  2857.       } else {
  2858.          flag = flag | ROAD;     // add road to this hex
  2859.          put_flags(t_grid,col,row,flag);
  2860.          ME_draw_roads(col,row);
  2861.          if (metro) {
  2862.             plot_city(col,row,0,FALSE);
  2863.             Remove((APTR)metro);
  2864.             AddHead((APTR)&city_list,(APTR)metro);
  2865.          }
  2866.       FI
  2867.       Delay(10L);    // key de-bounce
  2868.       return;
  2869.    }
  2870.  
  2871.  
  2872.    if (lbrush==HEX_CITY) {           // this means the editor is in "city mode"
  2873.       if (city_hereP(col,row) && (qual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))) {
  2874.             map_safe = FALSE;
  2875.             remove_city(col,row);
  2876.             plot_hex(col,row,get(t_grid,col,row));
  2877.       } else
  2878.          (void)user_plopcity(col,row);
  2879.    } else {                        // terrain mode
  2880.       if (qual & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  2881.          lbrush = HEX_OCEAN;  // can change this and not worry
  2882.       if (lbrush!=get(t_grid,col,row)) {
  2883.          if (city_hereP(col,row) && lbrush>HEX_MOUNTAINS) {
  2884.             // it sure looks like the user is trying to slip an invalid
  2885.             // hex type underneath an already existing city
  2886.             playSound(DONK_SOUND,64);
  2887.             if (rtEZRequestTags("You cannot put that kind of terrain\nunderneath a city.",
  2888.                "  Abort  |Kill City",NULL,NULL,
  2889.                RT_Window,        map_window,
  2890.                RT_ReqPos,        REQPOS_CENTERSCR,
  2891.                RT_LockWindow,    TRUE,
  2892.                RTEZ_Flags,       EZREQF_CENTERTEXT,
  2893.                TAG_DONE ))
  2894.                return;
  2895.             else
  2896.                remove_city(col,row);
  2897.          FI
  2898.          map_safe = FALSE;
  2899.          put(t_grid,col,row,lbrush);
  2900.          plot_hex(col,row,lbrush);
  2901.          if (city_hereP(col,row))
  2902.             plot_city(col,row,WHITE,FALSE);
  2903.       FI
  2904.    FI
  2905. }
  2906.  
  2907.  
  2908. void initialize_editor()
  2909. {
  2910.    if (!editor_menu_strip)
  2911.       build_editor_menu();    // prepare the drop-down menus for use
  2912.  
  2913.    // initialize some map stuff
  2914.    wrap = FALSE;
  2915.    width = MIN_WD;
  2916.    height = MIN_HT;
  2917.    if (alloc_map(&t_grid)==FALSE)
  2918.       clean_exit(2,"ERROR: Fatal RAM allocation disaster!");
  2919.    Move(rast_port,0,0);    ClearScreen(rast_port);
  2920.    flood_map(t_grid,HEX_OCEAN);     // default starting conditions
  2921.    xoffs = yoffs = 0;
  2922.    update_scrollers();
  2923.    ME_draw_map();
  2924.    map_safe = TRUE;
  2925. }
  2926.  
  2927.  
  2928. void editor_menu()
  2929. {
  2930.    struct IntuiMessage *message; // the message the IDCMP sends us
  2931.    static int col, row;
  2932.         
  2933.    // useful for interpreting IDCMP messages
  2934.    UWORD code;
  2935.    ULONG class;
  2936.    APTR object;
  2937.    UWORD qualifier;
  2938.  
  2939.    // attach the menu to my window
  2940.    SetMenuStrip(map_window,editor_menu_strip);
  2941.  
  2942.    // Enable menus one and two.
  2943.    OnMenu(map_window,FULLMENUNUM(0,-1,0));
  2944.    OnMenu(map_window,FULLMENUNUM(1,-1,0));
  2945.    OnMenu(map_window,FULLMENUNUM(2,-1,0));
  2946.  
  2947.    OffMenu(map_window,FULLMENUNUM(2,4,0));
  2948.  
  2949.    while (TRUE) {
  2950.       WaitPort(map_window->UserPort);
  2951.       while (message = GT_GetIMsg(map_window->UserPort)) {
  2952.          code = message->Code;  // MENUNUM
  2953.          object = message->IAddress;  // Gadget
  2954.          class = message->Class;
  2955.          qualifier = message->Qualifier;
  2956.          GT_ReplyIMsg(message);
  2957.          if (class==IDCMP_GADGETUP) {
  2958.             int ox = xoffs, oy = yoffs;
  2959.  
  2960.             if (scrolly(object,code))
  2961.                ME_smart_scroll(ox,oy);
  2962.          FI
  2963.          if (class==IDCMP_RAWKEY) {
  2964.             int ox = xoffs, oy = yoffs;
  2965.             int wo = (wrap ? WRAP_OVERLAP : 0);
  2966.  
  2967.             switch (code) {
  2968.                case 0x4C:  // up cursor
  2969.                   yoffs--;
  2970.                   if (qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  2971.                      yoffs -= disp_ht;
  2972.                   if (qualifier & IEQUALIFIER_CONTROL)
  2973.                      yoffs = -wo;
  2974.                   if (yoffs < -wo)
  2975.                      yoffs = -wo;
  2976.                   break;
  2977.                case 0x4D:  // down cursor
  2978.                   yoffs++;
  2979.                   if (qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  2980.                      yoffs += disp_ht;
  2981.                   if (qualifier & IEQUALIFIER_CONTROL)
  2982.                      yoffs = height-(disp_ht-wo);
  2983.                   if (yoffs>height-(disp_ht-wo))
  2984.                      yoffs = height-(disp_ht-wo);
  2985.                   break;
  2986.                case 0x4F:  // left cursor
  2987.                   xoffs--;
  2988.                   if (qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  2989.                      xoffs -= disp_wd;
  2990.                   if (qualifier & IEQUALIFIER_CONTROL)
  2991.                      xoffs = -wo;
  2992.                   if (xoffs < -wo)
  2993.                      xoffs = -wo;
  2994.                   break;
  2995.                case 0x4E:  // right cursor
  2996.                   xoffs++;
  2997.                   if (qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT))
  2998.                      xoffs += disp_wd;
  2999.                   if (qualifier & IEQUALIFIER_CONTROL)
  3000.                      xoffs = width-(disp_wd-wo);
  3001.                   if (xoffs>width-(disp_wd-wo))
  3002.                      xoffs = width-(disp_wd-wo);
  3003.             }
  3004.             update_scrollers();
  3005.             ME_smart_scroll(ox,oy);
  3006.          FI
  3007.          if (class==IDCMP_MOUSEMOVE) {
  3008.             abs_to_log(message->MouseX,message->MouseY,&col,&row);
  3009.             sprintf(bar,"Map Editor v5.9d                                      Hex Coords: %ld / %ld",col+1,row+1);
  3010.             //plot_text(250,15,"         ",WHITE,NULL,JAM1,&topaz11);
  3011.             //plot_text(250,15,foo,WHITE,NULL,JAM1,&topaz11);
  3012.             SetWindowTitles(map_window,bar, (UBYTE *)~0);
  3013.             
  3014.          FI
  3015.          if (class==IDCMP_MOUSEBUTTONS && code==SELECTDOWN)
  3016.             if (qualifier & IEQUALIFIER_CONTROL) {
  3017.                int storebrush = brush;
  3018.                brush = HEX_CITY;
  3019.                user_plot(message->MouseX,message->MouseY,qualifier);  // plot city
  3020.                brush = storebrush;
  3021.             } else
  3022.                user_plot(message->MouseX,message->MouseY,qualifier);
  3023.          if (class==IDCMP_MOUSEMOVE && brush!=HEX_CITY && left_buttonP())
  3024.             if (object != vert_scroller && object != horz_scroller)    
  3025.                 user_plot(message->MouseX,message->MouseY,qualifier);
  3026.          if (class==IDCMP_VANILLAKEY && code==' ') {
  3027.                 //code = ' ';
  3028.                 do_terrain_window();
  3029.                 while (INFO) {
  3030.                     do_info_window();
  3031.                     do_terrain_window();
  3032.                     continue;
  3033.                 OD
  3034.          FI
  3035.          if (class==MOUSEBUTTONS && code==MIDDLEDOWN) {
  3036.                 do_terrain_window();
  3037.                 while (INFO) {
  3038.                     do_info_window();
  3039.                     do_terrain_window();
  3040.                     continue;
  3041.                 OD
  3042.          FI
  3043.          
  3044.          if (class==IDCMP_VANILLAKEY && code=='i') 
  3045.                 do_info_window();
  3046.          if (class==IDCMP_MENUPICK) {  // MenuItems
  3047.             OffMenu(map_window,FULLMENUNUM(0,-1,0));
  3048.             OffMenu(map_window,FULLMENUNUM(1,-1,0));
  3049.             switch (MENUNUM(code)) {
  3050.                case 0:  // [Project] menu
  3051.                   switch (ITEMNUM(code)) {
  3052.                      case 0:  // load map...
  3053.                         MEdit = TRUE;
  3054.                         if (!map_safe)
  3055.                                 if (alert(map_window,"Load Map","Your map is not saved!\nAre you sure you want to Load another?","Cancel|Load"))
  3056.                                         break;
  3057.                         strcpy(map_filename,"");
  3058.                         rt_loadsave_map(LOAD);
  3059.                         break;
  3060.                      case 1:  // save map...
  3061.                         MEdit = TRUE;
  3062.                         strcpy(map_filename,"Untitled.MAP");
  3063.                         rt_loadsave_map(SAVE);
  3064.                         break;
  3065.                      case 2:  // resize map...
  3066.                         map_size_request();
  3067.                         break;
  3068.                      case 3:  // clear map
  3069.                         if (brush==HEX_CITY || HEX_ROADS) {
  3070.                            playSound(DONK_SOUND,64);
  3071.                            (void)alert(map_window,NULL,"I can't flood the map with that terrain!","Cancel");
  3072.                         } else {
  3073.                            flood_map(t_grid,brush);
  3074.                            ME_draw_map();
  3075.                           map_safe = TRUE;
  3076.                         FI
  3077.                         break;
  3078.                      case 4:  // Exit Map Editor
  3079.                         if (map_safe)
  3080.                            return;
  3081.                         if (alert(map_window,"Exit Map Editor","Your map is not saved!\nAre you sure you want to leave the editor?","Exit|Cancel"))
  3082.                            return;
  3083.                         break;
  3084.                      case 5:  // Quit
  3085.                         if (map_safe)
  3086.                             quit_program();
  3087.                         else
  3088.                             if (alert(map_window,"Exit Map Editor","Your map is not saved!\nAre you sure you want to QUIT the program?","Quit|Cancel"))
  3089.                                clean_exit(0,NULL);
  3090.  
  3091.                   }
  3092.                   break;
  3093.                case 1:  // [Terrain] menu
  3094.                   if (ITEMNUM(code)==0) {
  3095.                       //class = IDCMP_VANILLAKEY;
  3096.                       //code = ' ';
  3097.                       do_terrain_window();
  3098.                       while (INFO) {
  3099.                          do_info_window();
  3100.                          do_terrain_window();
  3101.                          continue;
  3102.                       OD
  3103.                   FI
  3104.                   if (ITEMNUM(code)>1)
  3105.                       menu_select_terrain();
  3106.                   if (ITEMNUM(code)>=18)
  3107.                       do_info_window();
  3108.                   break;
  3109.                case 2:  // [Other] menu
  3110.                   if (ITEMNUM(code)==0)
  3111.                      ME_world_view();
  3112.                   if (ITEMNUM(code)==1)
  3113.                      Random_Window();
  3114.                   if (ITEMNUM(code)==2)
  3115.                      do_stats_window();
  3116.                   if (ITEMNUM(code)==3)
  3117.                      do_city();
  3118.                   if (ITEMNUM(code)==4)
  3119.                      do_connect();
  3120.             }
  3121.             // editor_menu_strip->Flags = MENUENABLED;
  3122.             OnMenu(map_window,FULLMENUNUM(0,-1,0));
  3123.             OnMenu(map_window,FULLMENUNUM(1,-1,0));
  3124.             OnMenu(map_window,FULLMENUNUM(2,-1,0));
  3125.          FI
  3126.       OD
  3127.    OD
  3128. }
  3129.  
  3130.  
  3131. void map_editor()
  3132. {
  3133.    // having just arrived here from the main program module,
  3134.    // first thing is detach the main menu strip
  3135.    ClearMenuStrip(map_window);
  3136.    // change the title so the user knows where he is
  3137.    SetWindowTitles(map_window,"Map Editor v5.9d",(UBYTE *)~0);
  3138.    ModifyIDCMP(map_window,IDCMP_MAPEDIT);
  3139.    ReportMouse(TRUE,map_window);
  3140.    MEdit = TRUE;
  3141.    initialize_editor();
  3142.    editor_menu();
  3143.  
  3144.    // wipe out the map
  3145.    nuke_list(&city_list);
  3146.    free_map(&t_grid);
  3147.    free_map(&me_grid);
  3148.    Move(rast_port,0,0);    ClearScreen(rast_port);
  3149.    wrap = FALSE;
  3150.    MEdit = FALSE;
  3151.    zero_scrollers();
  3152.    // reset the title for the main module
  3153.    SetWindowTitles(map_window,"Top Level",(UBYTE *)~0);
  3154.    ReportMouse(FALSE,map_window);
  3155.    ModifyIDCMP(map_window,IDCMP_MENUPICK);
  3156.    // remove the map editor drop-down menus
  3157.    ClearMenuStrip(map_window);
  3158.    // re-attach the main menu strip before returning to the main module
  3159.    ResetMenuStrip(map_window,main_menu_strip);
  3160.  
  3161.    // free the menus which are no longer needed
  3162.    if (editor_menu_strip) {
  3163.       FreeMenus(editor_menu_strip);
  3164.       editor_menu_strip = NULL;
  3165.    FI
  3166. }
  3167.  
  3168. // end of listing
  3169.